Interface Number

Index

Methods

Methods

public abbr(precision?: number): string

Returns an abbreviated form of the number.

extra

[precision] will round to the given precision.

example

(1000).abbr() -> "1k" (1000000).abbr() -> "1m" (1280).abbr(1) -> "1.3k"

Parameters

  • precision?: number optional

    Rounding precision, default = 0.

Returns

string

Abbreviated string representation of the number.

public abs(): number

Determines the absolute value of the number.

example

(-3).abs() -> 3

Returns

number

Absolute value of the number.

public acos(): number

arccosine

Returns

number

public asin(): number

arcsine

Returns

number

public atan(): number

arctangent

Returns

number

public bytes(precision?: number, limit?: number): string

Returns an abbreviated form of the number, considered to be "Bytes".

extra

[precision] will round to the given precision. [limit] is the upper limit for the units. The default is %4%, which is "terabytes" (TB). If [limit] is %false%, the upper limit will be "exa".

example

(1000).bytes() -> "1kB" (1000).bytes(2) -> "0.98kB" ((10).pow(20)).bytes() -> "90,949,470TB" ((10).pow(20)).bytes(0, false) -> "87EB"

Parameters

  • precision?: number optional

    Rounding precision, default = 0.

  • limit?: number optional

    Upper limit for the units, default = 4 which is terabytes.

Returns

string

Abbreviated string representation of the number in bytes.

public bytes(precision?: number, limit?: boolean): string

Parameters

  • precision?: number optional
  • limit?: boolean optional

Returns

string

public ceil(precision?: number): number

Shortcut for %Math.ceil% that also allows a .

example

(3.241).ceil() -> 4 (-3.241).ceil() -> -3 (3.241).ceil(2) -> 3.25 (3748).ceil(-2) -> 3800

Parameters

  • precision?: number optional

    Rounding precision, default = 0.

Returns

number

Ceiling rounded number.

public chr(): string

Returns a string at the code point of the number.

example

(65).chr() -> "A" (75).chr() -> "K"

Returns

string

String from character code.

public cos(): number

cosine

Returns

number

public day(): number

see

millisecond

Returns

number

public dayAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public dayAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public dayAgo(): Date

see

millisecondAgo

Returns

Date

public dayBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public dayBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public dayFromNow(): Date

see

millisecondFromNow

Returns

Date

public days(): number

see

millisecond

Returns

number

public daysAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public daysAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public daysAgo(): Date

see

millisecondAgo

Returns

Date

public daysBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public daysBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public daysFromNow(): Date

see

millisecondFromNow

Returns

Date

public downto(num: number, fn?: (n: number) => void, step?: number): Array<number>

Returns an array containing numbers from the number down to .

extra

Optionally calls [fn] callback for each number in that array. [step] allows multiples greater than 1.

example

(8).downto(3) -> [8, 7, 6, 5, 4, 3] (8).downto(3, function(n) { // This function is called 6 times receiving n as the value. }); (8).downto(2, null, 2) -> [8, 6, 4, 2]

Parameters

  • num: number

    Number to count down to.

  • fn?: (n: number) => void optional

    Callback function to call for each number.

  • step?: number optional

    Number to subtract each iteration, default = 1.

Returns

Array<number>

number[] containing numbers from number down to .

public duration(locale?: string): string

Takes the number as milliseconds and returns a unit-adjusted localized string.

extra

This method is the same as %Date#relative% without the localized equivalent of "from now" or "ago". [locale] can be passed as the first (and only) parameter. Note that this method is only available when the dates package is included.

example

(500).duration() -> '500 milliseconds' (1200).duration() -> '1 second' (75).minutes().duration() -> '1 hour' (75).minutes().duration('es') -> '1 hora'

Parameters

  • locale?: string optional

    Locale to convert the ms to, default = currentLocale.

Returns

string

String representation of the duration in [locale].

public exp(): number

E^X

Returns

number

public floor(precision?: number): number

Shortcut for %Math.floor% that also allows a .

example

(3.241).floor() -> 3 (-3.841).floor() -> -4 (3.241).floor(2) -> 3.24 (3748).floor(-2) -> 3700

Parameters

  • precision?: number optional

    Rounding precision, default = 0.

Returns

number

Floor rounded number.

public format(place?: number, thousands?: string, decimal?: string): string

Formats the number to a readable string.

method

format([place] = 0, [thousands] = ',', [decimal] = '.')

extra

If [place] is %undefined%, will automatically determine the place. [thousands] is the character used for the thousands separator. [decimal] is the character used for the decimal point.

example

(56782).format() -> '56,782' (56782).format(2) -> '56,782.00' (4388.43).format(2, ' ') -> '4 388.43' (4388.43).format(2, '.', ',') -> '4.388,43'

Parameters

  • place?: number optional

    default = 0.

  • thousands?: string optional

    Thousands character, default = ','.

  • decimal?: string optional

    Decimal character, default = '.'.

Returns

string

String

public hex(pad?: number): string

Converts the number to hexidecimal.

method

hex([pad] = 1)

extra

[pad] will pad the resulting string to that many places.

example

(255).hex() -> 'ff'; (255).hex(4) -> '00ff'; (23654).hex() -> '5c66';

Parameters

  • pad?: number optional

    Number of characters to pad.

Returns

string

Hexidecimal number.

public hour(): number

see

millisecond

Returns

number

public hourAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public hourAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public hourAgo(): Date

see

millisecondAgo

Returns

Date

public hourBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public hourBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public hourFromNow(): Date

see

millisecondFromNow

Returns

Date

public hours(): number

see

millisecond

Returns

number

public hoursAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public hoursAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public hoursAgo(): Date

see

millisecondAgo

Returns

Date

public hoursBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public hoursBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public hoursFromNow(): Date

see

millisecondFromNow

Returns

Date

public isEven(): boolean

Returns true if the number is even.

example

(6).isEven() -> true (17).isEven() -> false

Returns

boolean

True if the number is even, otherwise false.

public isInteger(): boolean

Returns true if the number has no trailing decimal.

example

(420).isInteger() -> true (4.5).isInteger() -> false

Returns

boolean

True if the number is an integer, otherwise false.

public isMultipleOf(num: number): boolean

Returns true if the number is a multiple of .

example

(6).isMultipleOf(2) -> true (17).isMultipleOf(2) -> false (32).isMultipleOf(4) -> true (34).isMultipleOf(4) -> false

Parameters

  • num: number

    Number to check for multiple of.

Returns

boolean

True if the number is a multiple of .

public isOdd(): boolean

Returns true if the number is odd.

example

(3).isOdd() -> true (18).isOdd() -> false

Returns

boolean

True if the number is odd, otherwise false.

public log(base?: number): number

Returns the logarithm of the number with base , or natural logarithm of the number if is undefined.

example

(64).log(2) -> 6 (9).log(3) -> 2 (5).log() -> 1.6094379124341003

Parameters

  • base?: number optional

    default = Math.E.

Returns

number

Logarithm of the number with base .

public metric(precision?: number, limit?: number): string

Returns the number as a string in metric notation.

method

metric([precision] = 0, [limit] = 1)

extra

[precision] will round to the given precision. Both very large numbers and very small numbers are supported. [limit] is the upper limit for the units. The default is %1%, which is "kilo". If [limit] is %false%, the upper limit will be "exa". The lower limit is "nano", and cannot be changed.

example

(1000).metric() -> "1k" (1000000).metric() -> "1,000k" (1000000).metric(0, false) -> "1M" (1249).metric(2) + 'g' -> "1.25kg" (0.025).metric() + 'm' -> "25mm"

Parameters

  • precision?: number optional

    Rounding precision, default = 0.

  • limit?: number optional

    Upper limit for the metric units, default = 1 which is kilo.

Returns

string

Metric string notation for the number.

public metric(precision?: number, limit?: boolean): string

see

metric

limit

If false the upper limit for the metric units will be 'exa'.

Parameters

  • precision?: number optional
  • limit?: boolean optional

Returns

string

public millisecond(): number

Takes the number as a corresponding unit of time and converts to [unit].

method

unit

extra

Method names can be both singular and plural. Note that as "a month" is ambiguous as a unit of time, %months% will be equivalent to 30.4375 days, the average number in a month. Be careful using %months% if you need exact precision.

set

millisecond milliseconds second seconds minute minutes hour hours day days week weeks month months year years

example

(5).milliseconds() -> 5 (10).hours() -> 36000000 (1).day() -> 86400000

Returns

number

Number

public millisecondAfter(d: string, locale?: string): Date

Returns a date units after , where is the number.

method

[unit]After([d], [locale] = currentLocale)

extra

[d] will accept a date object, timestamp, or text format. Note that "months" is ambiguous as a unit of time. If the target date falls on a day that does not exist (ie. August 31 -> February 31), the date will be shifted to the last day of the month. Be careful using %monthsAfter% if you need exact precision. See @date_format for more.

set

millisecondAfter millisecondsAfter secondAfter secondsAfter minuteAfter minutesAfter hourAfter hoursAfter dayAfter daysAfter weekAfter weeksAfter monthAfter monthsAfter yearAfter yearsAfter

example

(5).daysAfter('tuesday') -> 5 days after tuesday of this week (1).yearAfter('January 23, 1997') -> January 23, 1998

Parameters

  • d: string

    Date to start from.

  • locale?: string optional

    Locale for return Date, default = currentLocale.

Returns

Date

Date units after .

public millisecondAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public millisecondAgo(): Date

Returns a date that is units ago.

method

[unit]Ago()

extra

Note that "months" is ambiguous as a unit of time. If the target date falls on a day that does not exist (ie. August 31 -> February 31), the date will be shifted to the last day of the month. Be careful using %monthsAgo% if you need exact precision.

set

millisecondAgo millisecondsAgo secondAgo secondsAgo minuteAgo minutesAgo hourAgo hoursAgo dayAgo daysAgo weekAgo weeksAgo monthAgo monthsAgo yearAgo yearsAgo

example

(5).weeksAgo() -> 5 weeks ago (1).yearAgo() -> January 23, 1996

Returns

Date

Date

public millisecondBefore(d: string, locale?: string): Date

Returns a date that is units before , where is the number.

method

[unit]Before([d], [locale] = currentLocale)

extra

[d] will accept a date object, timestamp, or text format. Note that "months" is ambiguous as a unit of time. If the target date falls on a day that does not exist (ie. August 31 -> February 31), the date will be shifted to the last day of the month. Be careful using %monthsBefore% if you need exact precision. See @date_format for more.

set

millisecondBefore millisecondsBefore secondBefore secondsBefore minuteBefore minutesBefore hourBefore hoursBefore dayBefore daysBefore weekBefore weeksBefore monthBefore monthsBefore yearBefore yearsBefore

example

(5).daysBefore('tuesday') -> 5 days before tuesday of this week (1).yearBefore('January 23, 1997') -> January 23, 1996

Parameters

  • d: string

    Date to start from.

  • locale?: string optional

    Locale for return Date, default = currentLocale.

Returns

Date

Date units before .

public millisecondBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public millisecondFromNow(): Date

Returns a date units from now.

method

[unit]FromNow()

extra

Note that "months" is ambiguous as a unit of time. If the target date falls on a day that does not exist (ie. August 31 -> February 31), the date will be shifted to the last day of the month. Be careful using %monthsFromNow% if you need exact precision.

set

millisecondFromNow millisecondsFromNow secondFromNow secondsFromNow minuteFromNow minutesFromNow hourFromNow hoursFromNow dayFromNow daysFromNow weekFromNow weeksFromNow monthFromNow monthsFromNow yearFromNow yearsFromNow

example

(5).weeksFromNow() -> 5 weeks ago (1).yearFromNow() -> January 23, 1998

Returns

Date

Date

public milliseconds(): number

see

millisecond

Returns

number

public millisecondsAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public millisecondsAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public millisecondsAgo(): Date

see

millisecondAgo

Returns

Date

public millisecondsBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public millisecondsBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public millisecondsFromNow(): Date

see

millisecondFromNow

Returns

Date

public minute(): number

see

millisecond

Returns

number

public minuteAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public minuteAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public minuteAgo(): Date

see

millisecondAgo

Returns

Date

public minuteBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public minuteBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public minuteFromNow(): Date

see

millisecondFromNow

Returns

Date

public minutes(): number

see

millisecond

Returns

number

public minutesAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public minutesAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public minutesAgo(): Date

see

millisecondAgo

Returns

Date

public minutesBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public minutesBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public minutesFromNow(): Date

see

millisecondFromNow

Returns

Date

public month(): number

see

millisecond

Returns

number

public monthAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public monthAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public monthAgo(): Date

see

millisecondAgo

Returns

Date

public monthBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public monthBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public monthFromNow(): Date

see

millisecondFromNow

Returns

Date

public months(): number

see

millisecond

Returns

number

public monthsAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public monthsAgo(): Date

see

millisecondAgo

Returns

Date

public monthsBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public monthsBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public monthsFromNow(): Date

see

millisecondFromNow

Returns

Date

public ordinalize(): string

Returns an ordinalized (English) string, i.e. "1st", "2nd", etc.

example

(1).ordinalize() -> '1st'; (2).ordinalize() -> '2nd'; (8).ordinalize() -> '8th';

Returns

string

Ordinalized string number equivalent.

public pad(place?: number, sign?: boolean, base?: number): string

Pads a number with "0" to .

method

pad( = 0, [sign] = false, [base] = 10)

extra

[sign] allows you to force the sign as well (+05, etc). [base] can change the base for numeral conversion.

example

(5).pad(2) -> '05' (-5).pad(4) -> '-0005' (82).pad(3, true) -> '+082'

Parameters

  • place?: number optional

    Pad up to this many characters, default = 0.

  • sign?: boolean optional

    True to force the sign (+/-), default = false.

  • base?: number optional

    The base of the new number, default = 10.

Returns

string

Padded number.

public pow(num: number): number

n^m

example

(3).pow(3) -> 27

Parameters

  • num: number

Returns

number

public round(precision?: number): number

Shortcut for %Math.round% that also allows a [precision].

example

(3.241).round() -> 3 (-3.841).round() -> -4 (3.241).round(2) -> 3.24 (3748).round(-2) -> 3800

Parameters

  • precision?: number optional

    Rounding precision, default = 0.

Returns

number

Rounded number to [precision].

public second(): number

see

millisecond

Returns

number

public secondAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public secondAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public secondAgo(): Date

see

millisecondAgo

Returns

Date

public secondBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public secondBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public secondFromNow(): Date

see

millisecondFromNow

Returns

Date

public seconds(): number

see

millisecond

Returns

number

public secondsAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public secondsAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public secondsAgo(): Date

see

millisecondAgo

Returns

Date

public secondsBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public secondsBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public secondsFromNow(): Date

see

millisecondFromNow

Returns

Date

public sin(): number

sine

Returns

number

public sqrt(): number

example

(1024).sqrt() -> 32

Returns

number

public tan(): number

tangent

Returns

number

public times(fn: (i: number) => void): number

Calls a number of times equivalent to the number.

example

(8).times(function(i) { // This function is called 8 times. });

Parameters

  • fn: (i: number) => void

    Callback function to call n times.

Returns

number

The original number.

public toNumber(): number

Returns a number. This is mostly for compatibility reasons.

example

(420).toNumber() -> 420

Returns

number

The original number.

public upto(num: number, fn?: Function, step?: number): Array<number>

Returns an array containing numbers from the number up to .

extra

Optionally calls [fn] callback for each number in that array. [step] allows multiples greater than 1.

example

(2).upto(6) -> [2, 3, 4, 5, 6] (2).upto(6, function(n) { // This function is called 5 times receiving n as the value. }); (2).upto(8, null, 2) -> [2, 4, 6, 8]

Parameters

  • num: number

    Number to count down to.

  • fn?: Function optional

    Callback function to call for each number.

  • step?: number optional

    Number to add each iteration, default = 1.

Returns

Array<number>

number[] containing numbers from number up to .

public week(): number

see

millisecond

Returns

number

public weekAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public weekAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public weekAgo(): Date

see

millisecondAgo

Returns

Date

public weekBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public weekBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public weekFromNow(): Date

see

millisecondFromNow

Returns

Date

public weeks(): number

see

millisecond

Returns

number

public weeksAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public weeksAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public weeksAgo(): Date

see

millisecondAgo

Returns

Date

public weeksBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public weeksBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public weeksFromNow(): Date

see

millisecondFromNow

Returns

Date

public year(): number

see

millisecond

Returns

number

public yearAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public yearAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public yearAgo(): Date

see

millisecondAgo

Returns

Date

public yearBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public yearBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public yearFromNow(): Date

see

millisecondFromNow

Returns

Date

public years(): number

see

millisecond

Returns

number

public yearsAfter(d: string, locale?: string): Date

see

millisecondAfter

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public yearsAfter(d: Date, locale?: string): Date

see

millisecondAfter

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public yearsAgo(): Date

see

millisecondAgo

Returns

Date

public yearsBefore(d: string, locale?: string): Date

see

millisecondBefore

Parameters

  • d: string
  • locale?: string optional

Returns

Date

public yearsBefore(d: Date, locale?: string): Date

see

millisecondBefore

Parameters

  • d: Date
  • locale?: string optional

Returns

Date

public yearsFromNow(): Date

see

millisecondFromNow

Returns

Date