Documentation

CRM_Utils_EnglishNumber
in package

Tags
copyright

CiviCRM LLC https://civicrm.org/licensing Utilities for rendering numbers as English.

Note: This file may be used in a standalone environment. Please ensure it remains self-sufficient (without needing any external services).

Table of Contents

Properties

$intervalsOfTen  : mixed
$lowNumbers  : mixed

Methods

isNumeric()  : bool
Determine if a string looks like
toCamelCase()  : string
toHyphen()  : string
toInt()  : int
Convert an English-style number to an int.

Properties

$intervalsOfTen

protected static mixed $intervalsOfTen = [9 => 'Ninety', 8 => 'Eighty', 7 => 'Seventy', 6 => 'Sixty', 5 => 'Fifty', 4 => 'Forty', 3 => 'Thirty', 2 => 'Twenty']

$lowNumbers

protected static mixed $lowNumbers = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen']

Methods

isNumeric()

Determine if a string looks like

public static isNumeric(string $english) : bool
Parameters
$english : string
Return values
bool

toCamelCase()

public static toCamelCase(int $num[, mixed $default = NULL ]) : string
Parameters
$num : int

Ex: 12 or 54.

$default : mixed = NULL

The default value to return if we cannot determine an English representation. If omitted or NULL, throws an exception. Tip: If you want to support high values as numerals, just pass the number again.

Return values
string

Ex: 'Twelve' or 'FiftyFour'.

toHyphen()

public static toHyphen(int $num[, mixed $default = NULL ]) : string
Parameters
$num : int

Ex: 12 or 54.

$default : mixed = NULL

The default value to return if we cannot determine an English representation. If omitted or NULL, throws an exception. Tip: If you want to support high values as numerals, just pass the number again.

Return values
string

Ex: 'twelve' or 'fifty-four'.

toInt()

Convert an English-style number to an int.

public static toInt(string $english) : int
Parameters
$english : string

Ex: 'TwentyTwo' or 'forty-four'

Return values
int

22 or 44


        
On this page

Search results