W3cubDocs

/Symfony 2.7

Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer

class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransformer

Transforms between an integer and a localized number with grouping (each thousand) and comma separators.

Constants

ROUND_CEILING

Rounds a number towards positive infinity.

Rounds 1.4 to 2 and -1.4 to -1.

ROUND_FLOOR

Rounds a number towards negative infinity.

Rounds 1.4 to 1 and -1.4 to -2.

ROUND_UP

Rounds a number away from zero.

Rounds 1.4 to 2 and -1.4 to -2.

ROUND_DOWN

Rounds a number towards zero.

Rounds 1.4 to 1 and -1.4 to -1.

ROUND_HALF_EVEN

Rounds to the nearest number and halves to the next even number.

Rounds 2.5, 1.6 and 1.5 to 2 and 1.4 to 1.

ROUND_HALF_UP

Rounds to the nearest number and halves away from zero.

Rounds 2.5 to 3, 1.6 and 1.5 to 2 and 1.4 to 1.

ROUND_HALF_DOWN

Rounds to the nearest number and halves towards zero.

Rounds 2.5 and 1.6 to 2, 1.5 and 1.4 to 1.

ROUND_HALFEVEN

Alias for {@link self::ROUNDHALFEVEN}.

ROUND_HALFUP

Alias for {@link self::ROUNDHALFUP}.

ROUND_HALFDOWN

Alias for {@link self::ROUNDHALFDOWN}.

Methods

__construct(int $precision, bool $grouping = false, int $roundingMode = self::ROUND_DOWN)

Constructs a transformer.

string transform(int|float $value)

Transforms a number type into localized number.

from NumberToLocalizedStringTransformer
int|float reverseTransform(string $value)

Transforms a localized number into an integer or float

Details

public __construct(int $precision, bool $grouping = false, int $roundingMode = self::ROUND_DOWN)

Constructs a transformer.

Parameters

int $precision Unused.
bool $grouping Whether thousands should be grouped.
int $roundingMode One of the ROUND_ constants in this class.

public string transform(int|float $value)

Transforms a number type into localized number.

Parameters

int|float $value Number value.

Return Value

string Localized value.

Exceptions

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

public int|float reverseTransform(string $value)

Transforms a localized number into an integer or float

Parameters

string $value The localized value

Return Value

int|float The numeric value

Exceptions

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