mediatekformation

NumberToLocalizedStringTransformer
in package
implements DataTransformerInterface

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

Tags
author

Bernhard Schussek bschussek@gmail.com

author

Florian Eckerstorfer florian@eckerstorfer.org

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_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.

Properties

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
throws
TransformationFailedException

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

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
throws
TransformationFailedException

if the given value is not numeric or if the value can not be transformed

Return values
string

Localized value

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

Search results