EnglishNumerals
extends NumberLocalizer
in package
Converts integers to and from English number words.
Table of Contents
Properties
- $textNormalizer : TextNormalizer
- Text normalizer applied before parsing numbers.
Methods
- __construct() : mixed
- Creates an English numeral localizer.
- formatCardinal() : string
- Formats an integer as English cardinal words.
- formatDigits() : string
- Formats an integer using Latin digits.
- formatOrdinal() : string
- Formats a non-zero integer as English ordinal words.
- parse() : NumberParseResult
- Parses an integer from localized digits or words.
- parseCardinal() : int|null
- Parses an integer from localized cardinal words.
- parseDigits() : int|null
- Parses an integer from Latin digits.
- parseOrdinal() : int|null
- Parses an integer from localized ordinal words.
- parseWords() : NumberParseResult
- Parses English cardinal or ordinal words into an integer.
Properties
$textNormalizer read-only
Text normalizer applied before parsing numbers.
protected
TextNormalizer
$textNormalizer
Methods
__construct()
Creates an English numeral localizer.
public
__construct([TextNormalizer|null $textNormalizer = null ]) : mixed
Parameters
- $textNormalizer : TextNormalizer|null = null
-
Text normalizer, or null to use English normalization.
formatCardinal()
Formats an integer as English cardinal words.
public
formatCardinal(int $value) : string
Parameters
- $value : int
-
Integer value to format.
Tags
Return values
string —English cardinal word representation.
formatDigits()
Formats an integer using Latin digits.
public
formatDigits(int $value[, int $minimumDigits = 1 ]) : string
Parameters
- $value : int
-
Integer value to format.
- $minimumDigits : int = 1
-
Minimum digit width excluding the sign.
Tags
Return values
string —Latin digit representation.
formatOrdinal()
Formats a non-zero integer as English ordinal words.
public
formatOrdinal(int $value) : string
Positive values are counted from the start of a sequence. Negative values are counted from the end of a sequence.
Parameters
- $value : int
-
Non-zero integer value to format.
Tags
Return values
string —English ordinal word representation.
parse()
Parses an integer from localized digits or words.
public
parse(string $text) : NumberParseResult
Digit parsing is tried before word parsing.
Parameters
- $text : string
-
Number representation to parse.
Tags
Return values
NumberParseResult —Parse result.
parseCardinal()
Parses an integer from localized cardinal words.
public
parseCardinal(string $text) : int|null
Parameters
- $text : string
-
Cardinal words to parse.
Tags
Return values
int|null —Parsed integer, or null when invalid or not cardinal.
parseDigits()
Parses an integer from Latin digits.
public
parseDigits(string $text) : int|null
Parameters
- $text : string
-
Digit representation to parse.
Tags
Return values
int|null —Parsed integer, or null when invalid.
parseOrdinal()
Parses an integer from localized ordinal words.
public
parseOrdinal(string $text) : int|null
Parameters
- $text : string
-
Ordinal words to parse.
Tags
Return values
int|null —Parsed integer, or null when invalid or not ordinal.
parseWords()
Parses English cardinal or ordinal words into an integer.
public
parseWords(string $text) : NumberParseResult
A valid input is an English cardinal number such as "zero", "forty-two", or "one million two hundred thousand three hundred forty-two". Hyphens in compound tens are treated as token separators, and input is parsed case-insensitively.
The final component may be an ordinal form, such as "first", "hundredth", "forty-second", or "one thousandth". The words "last" and phrases such as "second from last" or "second-to-last" are parsed as ordinal positions counted from the end, resulting in negative integer values.
A leading "minus" is accepted for cardinal numbers only, excluding zero.
Parameters
- $text : string
-
The string to parse.
Tags
Return values
NumberParseResult —Parse result.