Civil Date PHP Package

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

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
see
EnglishNumerals::parseWords()
override
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
throws
InvalidArgumentException

If the minimum digit width is less than one.

see
NumberLocalizer::parseDigits()
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
throws
InvalidArgumentException

If the value is zero.

see
EnglishNumerals::parseWords()
override
Return values
string

English ordinal word representation.

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
see
EnglishNumerals::formatCardinal()
EnglishNumerals::formatOrdinal()
override
Return values
NumberParseResult

Parse result.

On this page

Search results