![]()  | 
  
     v1.3.0.0
    
   | 
 
A few convenience methods to extend the standard Number prototype.
Public Member Functions | |
| number | round (number precision) | 
| number | clamp (number min, number max) | 
| number | constrain (number min, number max) | 
| string | format (format) | 
| Date | fromLocaleString (locale, numberString) | 
| string | toLocaleString (locale, format, precision) | 
| string | toLocaleCurrencyString (locale, symbol) | 
| number round | ( | number | precision | ) | 
Round value to precision decimal places. 
| number clamp | ( | number | min, | 
| number | max | ||
| ) | 
Constrain value to between min and max values. 
| number constrain | ( | number | min, | 
| number | max | ||
| ) | 
Alias for Number.clamp()
| string format | ( | format | ) | 
Formats this number according the specified .NET-style format string. 
This function emulates the .NET numeric types' *.ToString() methods (eg. Int32.ToString()). For example: 
See formatting string reference at https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#standard-format-specifiers
| Date fromLocaleString | ( | locale, | |
| numberString | |||
| ) | 
Returns a Number by parsing numberString using the conventions of the supplied locale. 
| locale | A Locale object, obtained with the global locale() method. If not specified, the default locale() will be used.  | 
| numberString | The input string to parse. | 
For example, using the German locale:
| string toLocaleString | ( | locale, | |
| format, | |||
| precision | |||
| ) | 
Converts the Number to a string suitable for the specified locale in the specified format, with the specified precision. 
| locale | A Locale object, obtained with the global locale() method. If not specified, the default locale() will be used.  | 
| format | One of the format specifier strings shown below. Default is ‘'f’` | 
| precision | Number of decimal places to show. Default is 2 decimals. | 
Valid formats are:
'f' Decimal floating point, e.g. 248.65 'e' Scientific notation using e character, e.g. 2.4865e+2 'E' Scientific notation using E character, e.g. 2.4865E+2 'g' Use the shorter of e or f 'G' Use the shorter of E or f
The following example shows a number formatted for the German locale:
You can apply toLocaleString() directly to constants, provided the decimal is included in the constant, e.g.
| string toLocaleCurrencyString | ( | locale, | |
| symbol | |||
| ) | 
Converts the Number to a currency using the currency and conventions of the specified locale.
If symbol is specified it will be used as the currency symbol.