Number Helpers
Table of Contents
number
Visit the: code | unit tests
{bytes}
Format a number to it's equivalent in bytes. If a string is passed, it's length will be formatted and returned.
Examples:
'foo' => 3 B
13661855 => 13.66 MB
825399 => 825.39 kB
1396 => 1.4 kB
Params
number
Number|Stringreturns
String
{addCommas}
Add commas to numbers
Params
num
Numberreturns
Number
{phoneNumber}
Convert a string or number to a formatted phone number.
Params
num
Number|String: The phone number to format, e.g.8005551212
returns
Number: Formatted phone number:(800) 555-1212
{toAbbr}
Abbreviate numbers to the given number of precision
. This is for
general numbers, not size in bytes.
Params
number
Numberprecision
Numberreturns
String
{toExponential}
Returns a string representing the given number in exponential notation.
Params
number
NumberfractionDigits
Number: Optional. An integer specifying the number of digits to use after the decimal point. Defaults to as many digits as necessary to specify the number.returns
Number
Example
{{toExponential number digits}};
{toFixed}
Formats the given number using fixed-point notation.
Params
number
Numberdigits
Number: (Optional) The number of digits to appear after the decimal point; this may be a value between 0 and 20. If this argument is omitted, it is treated as 0.returns
String: A string representing the given number using fixed-point notation.
Example
{{toFixed "1.1234" 2}}
//=> '1.12'
{toFloat}
Params
number
Numberreturns
Number
{toInt}
Params
number
Numberreturns
Number
{toPrecision}
Returns a string representing the Number
object to the specified precision.
Params
number
Numberprecision
Number: (Optional) An integer specifying the number of significant digits. If precison is not between 1 and 100 (inclusive), it will be coerced to0
.returns
String: A string representing a Number object in fixed-point or exponential notation rounded to precision significant digits.
Example
{{toPrecision "1.1234" 2}}
//=> '1.1'