Skip to main content

Number Operators

When we need to work with numbers, these operators will help with your markdown.

List of Operators

{{ 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 0
  • returns

{{ addCommas }}

Add commas to numbers

Params

  • num
  • returns

Example

{{addCommas 40000}}
<!-- results in: '40,000' -->

{{ phoneNumber }}

Convert a string or number to a formatted phone number.

Params

  • num 0: The phone number to format, e.g. 8005551212
  • returns : Formatted phone number: (800) 555-1212

Example

{{phoneNumber 8005551212}}
<!-- results in: '(800) 555-1212' -->

{{ toAbbr }}

Abbreviate numbers to the given number of precision. This is for general numbers, not size in bytes.

Params

  • number
  • precision
  • returns

Example

{{toAbbr 8005551212}}
<!-- results in: '8.01b' -->

{{ toExponential }}

Returns a string representing the given number in exponential notation.

Params

  • number
  • fractionDigits : 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

Example

{{toExponential number digits}}

{{ toFixed }}

Formats the given number using fixed-point notation.

Params

  • number
  • digits : (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 : A string representing the given number using fixed-point notation.

Example

{{toFixed "1.1234" 2}}
<!-- results in: '1.12' -->

{{ toFloat }}

Params

  • number
  • returns

{{ toInt }}

Params

  • number
  • returns

Example

{{toInt "1.1234"}}
<!-- results in: '1' -->

{{ toPrecision }}

Returns a string representing the Number object to the specified precision.

Params

  • number
  • precision : (Optional) An integer specifying the number of significant digits. If precison is not between 1 and 100 (inclusive), it will be coerced to 0.
  • returns : A string representing a Number object in fixed-point or exponential notation rounded to precision significant digits.

Example

{{toPrecision "1.1234" 2}}
//=> '1.1'