3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 * Utilities for rendering numbers as English.
20 * Note: This file may be used in a standalone environment. Please ensure it
21 * remains self-sufficient (without needing any external services).
23 class CRM_Utils_EnglishNumber
{
25 protected static $lowNumbers = [
48 protected static $intervalsOfTen = [
62 * @param mixed $default
63 * The default value to return if we cannot determine an English representation.
64 * If omitted or NULL, throws an exception.
65 * Tip: If you want to support high values as numerals, just pass the number again.
67 * Ex: 'Twelve' or 'FiftyFour'.
69 public static function toCamelCase($num, $default = NULL) {
70 if (isset(self
::$lowNumbers[$num])) {
71 return self
::$lowNumbers[$num];
74 $tens = (int) ($num / 10);
76 if (isset(self
::$intervalsOfTen[$tens])) {
78 return self
::$intervalsOfTen[$tens];
81 return self
::$intervalsOfTen[$tens] . self
::$lowNumbers[$last];
85 if ($default === NULL) {
86 throw new \
RuntimeException("Cannot convert number to English: " . (int) $num);
96 * @param mixed $default
97 * The default value to return if we cannot determine an English representation.
98 * If omitted or NULL, throws an exception.
99 * Tip: If you want to support high values as numerals, just pass the number again.
101 * Ex: 'twelve' or 'fifty-four'.
103 public static function toHyphen($num, $default = NULL) {
104 if (isset(self
::$lowNumbers[$num])) {
105 return strtolower(self
::$lowNumbers[$num]);
108 $tens = (int) ($num / 10);
110 if (isset(self
::$intervalsOfTen[$tens])) {
112 return strtolower(self
::$intervalsOfTen[$tens]);
115 return strtolower(self
::$intervalsOfTen[$tens]) . '-' . strtolower(self
::$lowNumbers[$last]);
119 if ($default === NULL) {
120 throw new \
RuntimeException("Cannot convert number to English: " . (int) $num);