3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
34 * Utilities for rendering numbers as English.
36 * Note: This file may be used in a standalone environment. Please ensure it
37 * remains self-sufficient (without needing any external services).
39 class CRM_Utils_EnglishNumber
{
41 protected static $lowNumbers = array(
64 protected static $intervalsOfTen = array(
78 * @param mixed $default
79 * The default value to return if we cannot determine an English representation.
80 * If omitted or NULL, throws an exception.
81 * Tip: If you want to support high values as numerals, just pass the number again.
83 * Ex: 'Twelve' or 'FiftyFour'.
85 public static function toCamelCase($num, $default = NULL) {
86 if (isset(self
::$lowNumbers[$num])) {
87 return self
::$lowNumbers[$num];
90 $tens = (int) ($num / 10);
92 if (isset(self
::$intervalsOfTen[$tens])) {
94 return self
::$intervalsOfTen[$tens];
97 return self
::$intervalsOfTen[$tens] . self
::$lowNumbers[$last];
101 if ($default === NULL) {
102 throw new \
RuntimeException("Cannot convert number to English: " . (int) $num);
112 * @param mixed $default
113 * The default value to return if we cannot determine an English representation.
114 * If omitted or NULL, throws an exception.
115 * Tip: If you want to support high values as numerals, just pass the number again.
117 * Ex: 'twelve' or 'fifty-four'.
119 public static function toHyphen($num, $default = NULL) {
120 if (isset(self
::$lowNumbers[$num])) {
121 return strtolower(self
::$lowNumbers[$num]);
124 $tens = (int) ($num / 10);
126 if (isset(self
::$intervalsOfTen[$tens])) {
128 return strtolower(self
::$intervalsOfTen[$tens]);
131 return strtolower(self
::$intervalsOfTen[$tens]) . '-' . strtolower(self
::$lowNumbers[$last]);
135 if ($default === NULL) {
136 throw new \
RuntimeException("Cannot convert number to English: " . (int) $num);