NumberToLocalizedStringTransformer

NumberToLocalizedStringTransformer

class NumberToLocalizedStringTransformer implements DataTransformerInterface

Transforms between a number type 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.

Methods

__construct($scale = null, $grouping = false, $roundingMode = self::ROUND_HALF_UP)
mixed transform(mixed $value)

Transforms a number type into localized number.

mixed reverseTransform(mixed $value)

Transforms a localized number into an integer or float.

Details

__construct($scale = null, $grouping = false, $roundingMode = self::ROUND_HALF_UP)

Parameters

$scale
$grouping
$roundingMode

mixed transform(mixed $value)

Transforms a number type into localized number.

Parameters

mixed $value The value in the original representation

Return Value

mixed The value in the transformed representation

Exceptions

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

mixed reverseTransform(mixed $value)

Transforms a localized number into an integer or float.

Parameters

mixed $value The value in the transformed representation

Return Value

mixed The value in the original representation

Exceptions

TransformationFailedException If the given value is not a string or if the value can not be transformed.
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部