PHP Класс Prado\I18N\core\NumberFormat

NumberFormat formats decimal numbers in any locale. The decimal number is formatted according to a particular pattern. These patterns can arise from the NumberFormatInfo object which is culturally sensitive. The NumberFormat class can be instantiated in many ways. E.g. create a invariant number formatter. $formatter = new NumberFormat(); create a number format for the french language locale. $fr = new NumberFormat('fr'); create a number format base on a NumberFormatInfo instance $numberInfo. $format = new NumberFormat($numberInfo); A normal decimal number can also be displayed as a currency or as a percentage. For example $format->format(1234.5); //Decimal number "1234.5" $format->format(1234.5,'c'); //Default currency "$1234.50" $format->format(0.25, 'p') //Percent "25%" Currency is formated using the localized currency pattern. For example to format the number as Japanese Yen: $ja = new NumberFormat('ja_JP'); Japanese currency pattern, and using Japanese Yen symbol $ja->format(123.14,'c','JPY'); //�?123 (Yen 123) For each culture, the symbol for each currency may be different.
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$formatInfo DateTimeFormatInfo The DateTimeFormatInfo, containing culture specific patterns and names.

Открытые методы

Метод Описание
__construct ( $formatInfo = null ) : NumberFormat Create a new number format instance. The constructor can be instantiated with a string that represent a culture/locale. Similarly, passing a CultureInfo or NumberFormatInfo instance will instantiated a instance for that particular culture.
format ( $number, $pattern = 'd', $currency = 'USD', $charset = 'UTF-8' ) : string For the number for a certain pattern. The valid patterns are 'c', 'd', 'e', 'p' or a custom pattern, such as "#.000" for 3 decimal places.

Защищенные методы

Метод Описание
formatDecimal ( $string ) : string Format the decimal places.
formatInteger ( $string ) : string For the integer, perform groupings and string padding.
setPattern ( $pattern ) : string Set the pattern to format against. The default patterns are retrieved from the NumberFormatInfo instance.

Описание методов

__construct() публичный Метод

Create a new number format instance. The constructor can be instantiated with a string that represent a culture/locale. Similarly, passing a CultureInfo or NumberFormatInfo instance will instantiated a instance for that particular culture.
public __construct ( $formatInfo = null ) : NumberFormat
Результат NumberFormat

format() публичный Метод

For the number for a certain pattern. The valid patterns are 'c', 'd', 'e', 'p' or a custom pattern, such as "#.000" for 3 decimal places.
public format ( $number, $pattern = 'd', $currency = 'USD', $charset = 'UTF-8' ) : string
Результат string formatted number string

formatDecimal() защищенный Метод

Format the decimal places.
protected formatDecimal ( $string ) : string
Результат string formatted decimal places.

formatInteger() защищенный Метод

For the integer, perform groupings and string padding.
protected formatInteger ( $string ) : string
Результат string formatted integer string with grouping

setPattern() защищенный Метод

Set the pattern to format against. The default patterns are retrieved from the NumberFormatInfo instance.
protected setPattern ( $pattern ) : string
Результат string a number format pattern.

Описание свойств

$formatInfo защищенное свойство

The DateTimeFormatInfo, containing culture specific patterns and names.
protected DateTimeFormatInfo,Prado\I18N\core $formatInfo
Результат DateTimeFormatInfo