IntegerToLocalizedStringTransformer
extends NumberToLocalizedStringTransformer
in package
Transforms between an integer and a localized number with grouping (each thousand) and comma separators.
Tags
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
- Constructs a transformer.
- 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()
Constructs a transformer.
public
__construct([bool $grouping = false ][, int $roundingMode = self::ROUND_DOWN ][, string|null $locale = null ]) : mixed
Parameters
- $grouping : bool = false
-
Whether thousands should be grouped
- $roundingMode : int = self::ROUND_DOWN
-
One of the ROUND_ constants in this class
- $locale : string|null = null
-
locale used for transforming
Return values
mixed —reverseTransform()
Transforms a localized number into an integer or float.
public
reverseTransform(mixed $value) : int|float|null
Parameters
- $value : mixed
-
The localized value
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