Home Reference Source

Function

Static Public Summary
public

format(val: number, opts: Object): *

Format a number using the default options.

public

formatFull(val: number, opts: Object): *

Format a full-flavor number using the default options.

public

formatShort(val: number, opts: Object): *

Format a short-flavor number using the default options.

public

parse(text: *, config: {}): *

public

requireDecimal(config: *): *

Static Public

public format(val: number, opts: Object): * source

import {format} from 'swarm-numberformat/src/format.js'

Format a number using the default options.

Params:

NameTypeAttributeDescription
val number
opts Object
  • optional

Return:

*

string

Example:

format(1e6)
// => "1.0000 million"
format(1e6, {sigfigs: 1})
// => "1 million"

public formatFull(val: number, opts: Object): * source

import {formatFull} from 'swarm-numberformat/src/format.js'

Format a full-flavor number using the default options. Identical to format()

Params:

NameTypeAttributeDescription
val number
opts Object
  • optional

Return:

*

string

Example:

format(1e6)
// => "1.0000 million"

public formatShort(val: number, opts: Object): * source

import {formatShort} from 'swarm-numberformat/src/format.js'

Format a short-flavor number using the default options.

Params:

NameTypeAttributeDescription
val number
opts Object
  • optional

Return:

*

string

Example:

format(1e6)
// => "1.00M"

public parse(text: *, config: {}): * source

import {parse} from 'swarm-numberformat/src/parse.js'

Params:

NameTypeAttributeDescription
text *
config {}
  • optional
  • default: {}

Return:

*

public requireDecimal(config: *): * source

import {requireDecimal} from 'swarm-numberformat/src/decimal.js'

Params:

NameTypeAttributeDescription
config *

Return:

*