NumberToLocalizedStringTransformer
in package
implements
DataTransformerInterface
Transforms between a number type and a localized number with grouping (each thousand) and comma separators.
Tags
Interfaces, Classes, Traits and Enums
- DataTransformerInterface
- Transforms a value between different representations.
Table of Contents
- ROUND_CEILING = \NumberFormatter::ROUND_CEILING
- Rounds a number towards positive infinity.
- ROUND_DOWN = \NumberFormatter::ROUND_DOWN
- Rounds a number towards zero.
- ROUND_FLOOR = \NumberFormatter::ROUND_FLOOR
- Rounds a number towards negative infinity.
- ROUND_HALF_DOWN = \NumberFormatter::ROUND_HALFDOWN
- Rounds to the nearest number and halves towards zero.
- ROUND_HALF_EVEN = \NumberFormatter::ROUND_HALFEVEN
- Rounds to the nearest number and halves to the next even number.
- ROUND_HALF_UP = \NumberFormatter::ROUND_HALFUP
- Rounds to the nearest number and halves away from zero.
- ROUND_UP = \NumberFormatter::ROUND_UP
- Rounds a number away from zero.
- $grouping : mixed
- $roundingMode : mixed
- $locale : mixed
- $scale : mixed
- __construct() : mixed
- reverseTransform() : int|float|null
- Transforms a localized number into an integer or float.
- transform() : string
- Transforms a number type into localized number.
- getNumberFormatter() : NumberFormatter
- Returns a preconfigured \NumberFormatter instance.
- round() : int|float
- Rounds a number according to the configured scale and rounding mode.
Constants
ROUND_CEILING
Rounds a number towards positive infinity.
public
mixed
ROUND_CEILING
= \NumberFormatter::ROUND_CEILING
Rounds 1.4 to 2 and -1.4 to -1.
ROUND_DOWN
Rounds a number towards zero.
public
mixed
ROUND_DOWN
= \NumberFormatter::ROUND_DOWN
Rounds 1.4 to 1 and -1.4 to -1.
ROUND_FLOOR
Rounds a number towards negative infinity.
public
mixed
ROUND_FLOOR
= \NumberFormatter::ROUND_FLOOR
Rounds 1.4 to 1 and -1.4 to -2.
ROUND_HALF_DOWN
Rounds to the nearest number and halves towards zero.
public
mixed
ROUND_HALF_DOWN
= \NumberFormatter::ROUND_HALFDOWN
Rounds 2.5 and 1.6 to 2, 1.5 and 1.4 to 1.
ROUND_HALF_EVEN
Rounds to the nearest number and halves to the next even number.
public
mixed
ROUND_HALF_EVEN
= \NumberFormatter::ROUND_HALFEVEN
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.
public
mixed
ROUND_HALF_UP
= \NumberFormatter::ROUND_HALFUP
Rounds 2.5 to 3, 1.6 and 1.5 to 2 and 1.4 to 1.
ROUND_UP
Rounds a number away from zero.
public
mixed
ROUND_UP
= \NumberFormatter::ROUND_UP
Rounds 1.4 to 2 and -1.4 to -2.
Properties
$grouping
protected
mixed
$grouping
$roundingMode
protected
mixed
$roundingMode
$locale
private
mixed
$locale
$scale
private
mixed
$scale
Methods
__construct()
public
__construct([int $scale = null ][, bool|null $grouping = false ][, int|null $roundingMode = self::ROUND_HALF_UP ][, string $locale = null ]) : mixed
Parameters
- $scale : int = null
- $grouping : bool|null = false
- $roundingMode : int|null = self::ROUND_HALF_UP
- $locale : string = null
Return values
mixed —reverseTransform()
Transforms a localized number into an integer or float.
public
reverseTransform(string $value) : int|float|null
Parameters
- $value : string
-
The localized value
Tags
Return values
int|float|null —The numeric value
transform()
Transforms a number type into localized number.
public
transform(int|float|null $value) : string
Parameters
- $value : int|float|null
-
Number value
Tags
Return values
string —Localized value
getNumberFormatter()
Returns a preconfigured \NumberFormatter instance.
protected
getNumberFormatter() : NumberFormatter
Return values
NumberFormatter —round()
Rounds a number according to the configured scale and rounding mode.
private
round(int|float $number) : int|float
Parameters
- $number : int|float
-
A number
Return values
int|float —The rounded number