W3cubDocs

/Symfony 2.7

Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer

class PercentToLocalizedStringTransformer implements DataTransformerInterface

Transforms between a normalized format (integer or float) and a percentage value.

Constants

FRACTIONAL
INTEGER

Methods

__construct(int $precision = null, string $type = null)

Constructor.

string transform(int|float $value)

Transforms between a normalized format (integer or float) into a percentage value.

int|float reverseTransform(string $value)

Transforms between a percentage value into a normalized format (integer or float).

Details

public __construct(int $precision = null, string $type = null)

Constructor.

Parameters

int $precision The precision
string $type One of the supported types

Exceptions

UnexpectedTypeException if the given value of type is unknown

See also

self::$types for a list of supported types

public string transform(int|float $value)

Transforms between a normalized format (integer or float) into a percentage value.

Parameters

int|float $value Normalized value

Return Value

string Percentage value

Exceptions

TransformationFailedException If the given value is not numeric or if the value could not be transformed.

public int|float reverseTransform(string $value)

Transforms between a percentage value into a normalized format (integer or float).

Parameters

string $value Percentage value.

Return Value

int|float Normalized value.

Exceptions

TransformationFailedException If the given value is not a string or if the value could not be transformed.