numbers

Namespace

numbers

Description:
  • Does number formatting and given a locale.
    Because method names are going to be used in templates, we keep them short, but descriptive.
    Method names are nouns describing what they return (rather than verbs), e.g. .number() and .ordinal()

    Methods ususally take one argument, and an additional options dictionary. See options for full documentation of available options.

    Some methods can be chained, for readability: numberText(4).upper() is equivalent to upper(numberText(4)).

    Methods with numerical input will accept a number, a numberlike text, or an array or object. In the latter case, it will use the length of those. This often makes sense semantically in template environment, where you can now write things like (Pug syntax): There are #{number(new_parties)} new #{plural(new_parties, "party", "parties")} in the parliament: #{list(new_parties)}

Methods

(static) abs(val) → {string}

Description:
  • Return an absolute number (a number without sign). This just is a shortcut to Math.abs().
Example
// returns 3.14
abs(-3.14)
Parameters:
Name Type Description
val number A number to make absolute
Returns:
An absolute number
Type
string

(static) approximateBillions(number, opts) → {string}

Description:
  • ”almost 2 billions”, and similar
Example

sv

// returns 'omkring 2 miljarder'
approximateBillions(1_950_000_000)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
1_000_000_000 What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
2 Diff (percent) to treat as 'same'
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
an approximation
Type
string

(static) approximateBillionsPretty(number, opts) → {string}

Description:
  • ”almost two billionsPretty”, and similar
Example

sv

// returns 'omkring två miljarder'
approximateBillions(1_950_000_000)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
1_000_000_000 What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt string <optional>
2 Diff (percent) to treat as 'same'
decimalDigits number <optional>
1 Number of fraction digits to show
gender string <optional>
"neuter" Grammatical gender
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
Returns:
an approximation
Type
string

(static) approximateBillionsText(number, opts) → {string}

Description:
  • ”almost two billions”, and similar
Example

sv

// returns 'omkring två miljarder'
approximateBillionsText(1_950_000_000)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
1_000_000_000 What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt string <optional>
2 Diff (percent) to treat as 'same'
decimalDigits number <optional>
1 Number of fraction digits to show
gender string <optional>
"neuter" Grammatical gender
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
an approximation
Type
string

(static) approximateLargeNumber(number, opts) → {string}

Description:
  • ”almost 2 billions”, and similar
Example

sv

// returns 'omkring 2 miljarder'
approximateLargeNumber(1_950_000_000)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
What power of ten to round to. Default is dynamic, based on number size.
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
largeNumberLimit number <optional>
Above what limit do we spell-out numbers? A language specific default will be used if none given.
Returns:
an approximation
Type
string

(static) approximateLargeNumberPretty(number, opts) → {string}

Description:
  • ”almost two billions”, and similar
Example

sv

// returns 'omkring två miljarder'
approximateLargeNumberPretty(1_950_000_000)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
What power of ten to round to. Default is dynamic, based on number size.
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
gender string <optional>
"neuter" Grammatical gender
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
largeNumberLimit number <optional>
Above what limit do we spell-out numbers? A language specific default will be used if none given.
Returns:
an approximation
Type
string

(static) approximateLargeNumberText(number, opts) → {string}

Description:
  • ”almost two billions”, and similar
Example

sv

// returns 'omkring två miljarder'
approximateLargeNumberText(1_950_000_000)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
What power of ten to round to. Default is dynamic, based on number size.
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
gender string <optional>
"neuter" Grammatical gender
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
largeNumberLimit number <optional>
Above what limit do we spell-out numbers? A language specific default will be used if none given.
Returns:
an approximation
Type
string

(static) approximateMillions(number, opts) → {string}

Description:
  • ”almost 2 millions”, and similar
Example

sv

// returns 'omkring 2 miljoner'
approximateMillions(1_950_000)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
1_000_000 What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt string <optional>
2 Diff (percent) to treat as 'same'
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
an approximation
Type
string

(static) approximateMillionsPretty(number, opts) → {string}

Description:
  • ”almost två millions”, and similar
Example

sv

// returns 'omkring två miljoner'
approximateMillionsPretty(1_950_000)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
1_000_000 What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt string <optional>
2 Diff (percent) to treat as 'same'
decimalDigits number <optional>
1 Number of fraction digits to show
gender string <optional>
"neuter" Grammatical gender
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
Returns:
an approximation
Type
string

(static) approximateMillionsText(number, opts) → {string}

Description:
  • ”almost two millions”, and similar
Example

sv

// returns 'omkring två miljoner'
approximateMillionsText(1_950_000)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
1_000_000 What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt string <optional>
2 Diff (percent) to treat as 'same'
decimalDigits number <optional>
1 Number of fraction digits to show
gender string <optional>
"neuter" Grammatical gender
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
an approximation
Type
string

(static) approximateMultiplier(number, opts) → {string}

Description:
  • Combine approcimate with multiplier, for numbers > 1
Example

sv

// returns 'drygt dubbel så många'
approximateMultiplier(2.3, "många")
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
1 What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
gender string <optional>
"neuter" Gender, in languages where it matters
denominator number <optional>
Keep the denominator below this in fractions
forceDenominator boolean <optional>
Force the denominator to given value in fractions
Returns:
an approximation
Type
string

(static) approximateMultiplierPretty(number, opts) → {string}

Description:
  • Combine approcimate with multiplier, for numbers > 1
Example

sv

// returns 'drygt dubbelt så många'
approximateMultiplierPretty(2.3, "många")
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
1 What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
gender string <optional>
"neuter" Gender, in languages where it matters
denominator number <optional>
Keep the denominator below this in fractions
forceDenominator boolean <optional>
Force the denominator to given value in fractions
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
Returns:
an approximation
Type
string

(static) approximateMultiplierText(number, opts) → {string}

Description:
  • Combine approcimate with multiplier, for numbers > 1
Example

sv

// returns 'drygt dubbelt så många'
approximateMultiplier(2.3, "många")
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
1 What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
gender string <optional>
"neuter" Gender, in languages where it matters
denominator number <optional>
Keep the denominator below this in fractions
forceDenominator boolean <optional>
Force the denominator to given value in fractions
Returns:
an approximation
Type
string

(static) approximately(number, opts) → {string}

Description:
  • Approximate will round off, and describe a number, in terms like ”slightly less than”.
Example

sv

// returns 'knappt 1 000'
approximately(992)

// returns 'lite mindre än 1 000'
approximately(992, {less: "lite mindre än", more: "lite drygt"})
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
an approximation
Type
string

(static) approximatelyInteger(number, opts) → {string}

Description:
  • Approximate will round off, and describe a number, in terms like ”slightly less than”. This is an alias for `approximately(val, {decimalDigits: 1})`
Example

sv

// returns 'drygt 1'
approximatelyInteger(1.1)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt= string <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
an approximation
Type
string

(static) approximatelyIntegerPretty(number, opts) → {string}

Description:
  • Approximate will round off, and describe a number, in terms like ”slightly less than”. This is an alias for `approximatelyPretty(val, {decimalDigits: 1})`
Example

sv

// returns 'drygt ett'
approximatelyIntegerPretty(1.1)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
gender string <optional>
"neuter" Grammatical gender
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
Returns:
an approximation
Type
string

(static) approximatelyIntegerText(number, opts) → {string}

Description:
  • Approximate will round off, and describe a number, in terms like ”slightly less than”. This is an alias for `approximatelyText(val, {decimalDigits: 1})`
Example

sv

// returns 'drygt ett'
approximatelyIntegerText(1.1)
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
gender string <optional>
"neuter" Grammatical gender
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
an approximation
Type
string

(static) approximatelyPretty(number, opts) → {string}

Description:
  • Approximate will round off, and describe a number, in terms like ”slightly less than three”.
Example

sv

// returns 'knappt 1 000'
approximatelyPretty(992)

// returns 'lite mindre än ett'
approximatelyPretty(0.99, {less: "lite mindre än", more: "lite drygt"})
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
gender string <optional>
"neuter" Grammatical gender
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
Returns:
an approximation
Type
string

(static) approximatelyText(number, opts) → {string}

Description:
  • Approximate will round off, and describe a number, in terms like ”slightly less than three”.
Example

sv

// returns 'knappt tusen'
approximatelyText(992)

// returns 'lite mindre än ett'
approximatelyText(0.99, {less: "lite mindre än", more: "lite drygt"})
Parameters:
Name Type Description
number number to approximate
opts object An options object
Properties
Name Type Attributes Default Description
exact string <optional>
"" Affix for exakt match
less string <optional>
"knappt" Affix for less than
more string <optional>
"drygt" Affix for more than
same string <optional>
"omkring" Affix for almost exakt match
precision string <optional>
What power of ten to round to
significantDigits string <optional>
Number of significant digits to round to
equalAt number <optional>
Diff (percent) to treat as 'same'. Default is dynamic, based on number size.
decimalDigits number <optional>
1 Number of fraction digits to show
gender string <optional>
"neuter" Grammatical gender
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
an approximation
Type
string

(static) billions(val, optsopt) → {string}

Description:
  • Print large numbers as a number of billions.
    This is an alias for largeNumber(val, {magnitude: 9})
Example

sv

// returns '1,9 miljarder'
billions("1893193123")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) billionsChange(val, optsopt) → {string}

Description:
  • Print large numbers as a number of billions.
    This is an alias for largeNumberChange(val, {magnitude: 9})
Example

sv

// returns '+1,9 miljarder'
billionsChange("1893193123")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) billionsChangeShort(val, optsopt) → {string}

Description:
  • Print large numbers as a number of billions.
    This is an alias for largeNumberChangeShort(val, {magnitude: 9})
Example

sv

// returns '+1,9 md'
billionsChangeShort("189319312
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) billionsPretty(val, optsopt) → {string}

Description:
  • Print large numbers as a number of billions.
Example

sv

// returns 'två miljarder'
billionsPretty("2_000_000_000")
// returns '2,1 miljarder'
billionsPretty("2_100_000_000")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Returns:
Textual representation
Type
string

(static) billionsShort(val, optsopt) → {string}

Description:
  • Print large numbers as a number of billions.
    This is an alias for largeNumberShort(val, {magnitude: 9})
Example

sv

// returns '1,9 md'
billionsShort("1893193123")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) billionsText(val, optsopt) → {string}

Description:
  • Print large numbers as a number of millions.
    This is an alias for largeNumber(val, {magnitude: 6})
Example

sv

// returns 'två miljarder'
billionsText("2_000_000_000")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Returns:
Textual representation
Type
string

(static) change(number, optopt) → {string}

Description:
  • Print out a change or difference, prefixed with a plus or minus sign. For most languages this is probably equal to sign(diff) + number(abs(diff)), but this is a more language agnostic implementation, expected to work for any of the >270 modern languages covered by CLDR.
Example

sv

// returns '+3,1'
change(3.14)
// returns '±0'
change(0)
// returns '+0'
change(0, {zeroSign: 1})
// returns '-3'
change(-3)
Parameters:
Name Type Attributes Description
number number A numerical value
opt object <optional>
Options
Properties
Name Type Attributes Default Description
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
decimalDigits number <optional>
1 Number of decimal digits
numberSystem string <optional>
Numbering system, if non-default. Will not work with complex numbering systems, like Amharic.
forceDecimalDigits boolean <optional>
false Keep trailing zeros
precision number <optional>
A indicative number to round to, e.g. 1_000
significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
An affixed number
Type
string

(static) changeInteger(number, optopt) → {string}

Description:
  • Print out a change or difference, prefixed with a plus or minus sign, as an integer. For most languages this is probably equal to sign(diff) + number(abs(diff)), but this is a more language agnostic implementation, expected to work for any of the >270 modern languages covered by CLDR. Note that this function does NOT call integer(), but is merely a shorthand method for change(X, {decimalDigits: 0}). This could lead to some inconsistencies with other *integer* methods.
Example

sv

// returns '+3,1'
change(3.14)
// returns '0'
change(0)
// returns '+0'
change(0, {zeroSign: 1})
// returns '-3'
change(-3)
Parameters:
Name Type Attributes Description
number number A numerical value
opt object <optional>
Options
Properties
Name Type Attributes Default Description
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
Numbering system, if non-default. Will not work with complex numbering systems, like Amharic.
precision number <optional>
A indicative number to round to, e.g. 1_000
significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
An affixed number
Type
string

(static) changePercent(val, optsopt) → {string}

Description:
  • Format change in percent. This is rougly equal to doing `val => change(val * 100)`
Examples

sv

// returns '+15,1'
changePercent(0.151)

en

// returns '+15.1'
changePercent(0.151)
// returns '+15'
changePercent(0.151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
opt.precision number <optional>
A indicative number to round to, e.g. 1_000
opt.significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
A textual representation
Type
string

(static) changePercentInteger(val, optsopt) → {string}

Description:
  • Format change in percent. This is rougly equal to doing `val => changeInteger(val * 100)`
Example

sv

// returns '+15'
changePercentInteger(0.151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
opt.precision number <optional>
A indicative number to round to, e.g. 1_000
opt.significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
A textual representation
Type
string

(static) changePercentShort(val, optsopt) → {string}

Description:
  • Format change in percent, including a percent sign
Examples

sv

// returns '+15,1 %'
changePercentShort(0.151)

en

// returns '+15.1%'
changePercentShort(0.151)
// returns '+15%'
changePercentShort(0.151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
opt.precision number <optional>
A indicative number to round to, e.g. 1_000
opt.significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
A textual representation
Type
string

(static) changePercentShortInteger(val, optsopt) → {string}

Description:
  • Format change in percent, including a percent sign
Example

sv

// returns '+15 %'
changePercentShortInteger(0.151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
opt.precision number <optional>
A indicative number to round to, e.g. 1_000
opt.significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
A textual representation
Type
string

(static) changePermille(val, optsopt) → {string}

Description:
  • Format change in percent. This is rougly equal to doing `val => change(val * 1000)`
Examples

sv

// returns '+15,1'
changePermille(0.0151)

en

// returns '+15.1'
changePermille(0.0151)
// returns '+15'
changePermille(0.0151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
opt.precision number <optional>
A indicative number to round to, e.g. 1_000
opt.significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
A textual representation
Type
string

(static) changePermilleInteger(val, optsopt) → {string}

Description:
  • Format change in per mille. This is rougly equal to doing `val => changeInteger(val * 1000)`
Example

sv

// returns '+15'
changePermilleInteger(0.0151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
opt.precision number <optional>
A indicative number to round to, e.g. 1_000
opt.significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
A textual representation
Type
string

(static) changePermilleShort(val, optsopt) → {string}

Description:
  • Format change in per mille, including a per mille sign
Examples

sv

// returns '+15,1 ‰'
changePermilleShort(0.0151)

en

// returns '+15.1‰'
changePermilleShort(0.0151)
// returns '+15‰'
changePermilleShort(0.0151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
opt.precision number <optional>
A indicative number to round to, e.g. 1_000
opt.significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
A textual representation
Type
string

(static) changePermilleShortInteger(val, optsopt) → {string}

Description:
  • Format change in per mille, including a per mille sign
Example

sv

// returns '+15 ‰'
changePermilleShortInteger(0.151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
opt.precision number <optional>
A indicative number to round to, e.g. 1_000
opt.significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
A textual representation
Type
string

(static) fraction(val, optsopt) → {string}

Description:
  • Write a number as a fraction. Note that there are many ways to express fractions in most languages. fraction, fractionShort and fractionText provide reasonable defaults, but to tailorsuit the output to your needs, you may want to create your own function using the utility method fractionParts.
Example

sv

// returns '2 ¹⁄₄'
fraction(2.25)
// returns 'varannan'
fraction(0.5, {"1/2": varannan})
// returns '¹⁄₃'
fraction(0.33333)
// returns '³⁄₁₀₀'
fraction(0.03, {denominator: 100})
// returns '³⁄₁₀'
fraction(0.33333, {denominator: 10, forceDenominator: true})
// returns '൳'
fraction(0.25, {numberSystem: "mlym"})
Parameters:
Name Type Attributes Description
val number A number to create a fraction from
opts object <optional>
Options
Properties
Name Type Attributes Default Description
denominator number <optional>
10 Keep the denominator below this value
forceDenominator boolean <optional>
false Force the denominator to the given value
numberSystem string <optional>
Number system, if non-default
string <optional>
Add any special case rules as a minimal fraction, e.g. "1/2"
Returns:
Whole number part, numerator, and denominator formated as a fraction
Type
string

(static) fractionParts(val, optsopt) → {Array}

Description:
  • Utility mthod for creating fractions. This is intended for use in other, template level functions.
Example
// returns [3, 1, 5, 0]
fractionParts(3.2)
// returns [3, 2, 10, 0]
fractionParts(3.2, {denominator: 10, forceDenominator: true})
// Template function example:
format("{1} out of {2}", fractionParts(share))
Parameters:
Name Type Attributes Description
val number A number to create a fraction from
opts object <optional>
Options
Properties
Name Type Attributes Description
denominator number <optional>
Keep the denominator below this
forceDenominator boolean <optional>
Force the denominator to given value
Returns:
[whole, numerator, denominator, difference]
Type
Array

(static) fractionText(val, optsopt) → {string}

Description:
  • Write a number as a fraction, using textual representation.
    Note that there are many ways to express fractions in most languages. fraction, and fractionText provide reasonable defaults, but to tailorsuit the output to your needs, you may want to create your own function using the utility method fractionParts.
Example

sv

// returns 'en fjärdedel'
fractionText(0.250001)
// returns 'ett och en fjärdedel'
fractionText(1.25)
// returns 'ett och tre fjärdedelar'
fractionText(1.75)
// returns 'en och en fjärdedels apelsin'
fractionText(1.25, {gender: "neuter"}) + "s apelsin"
// returns 'ett och ett fjärdedels äpple'
fractionText(1.25, {gender: "reale"}) + "s äpple"
// returns 'varannan'
fractionText(0.5, {"1/2": varannan})
Parameters:
Name Type Attributes Description
val number A number to create a fraction from
opts object <optional>
Options
Properties
Name Type Attributes Default Description
gender string <optional>
Gender, if relevant
style string <optional>
Use style to select special variants of some fractions. {style: 'noun'} will return 'hälften' for 0.5 in Swedish, where the default is 'en halv' or 'ett halvt'. Will be overridden by any special case rules. This option may be removed in the future.
denominator number | 'pretty' <optional>
5 Keep the denominator below this value
forceDenominator boolean <optional>
false Force the denominator to the given value
string <optional>
Add any special case rules as a minimal fraction, e.g. "1/2"
Returns:
Whole number part, numerator, and denominator expressed as a fraction
Type
string

(static) integer(val, optsopt) → {string}

Description:
  • This is the same as number(number, {decimalDigits: 0})
Example

sv

// returns '19'
integer(19.12)
// returns 'XLIX'
integer(49, {numberSystem: "roman"})
Parameters:
Name Type Attributes Description
val number A number
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) integerPretty(val, optsopt) → {string}

Description:
  • Spell out low integers, use numerical representation for higher numbers, if that is preferred in this language.
    This is the same as numberPretty(number, {decimalDigits: 0})
Example

sv

// returns 'ett'
integerPretty(1)
// returns '19'
integerPretty(19.12)
// returns 'nitton'
integerPretty(19.12, {prettyLimit: 20})
Parameters:
Name Type Attributes Description
val number A number
opts object <optional>
Options
Properties
Name Type Attributes Default Description
gender string <optional>
"neuter" Gender, in languages where it matters
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) integerText(val, optsopt) → {string}

Description:
  • Spell out integers
    This is the same as numberText(number, {decimalDigits: 0})
Example

sv

// returns 'ett'
integerText(1)

// returns 'nitton'
integerText(19.12)
Parameters:
Name Type Attributes Description
val number A number
opts object <optional>
Options
Properties
Name Type Attributes Default Description
gender string <optional>
"neuter" Gender, in languages where it matters
Returns:
A textual representation
Type
string

(static) largeNumber(val, optsopt) → {string}

Description:
  • Print large numbers using affixes like “million”
Examples

sv

// returns '1,9 miljoner'
largeNumber("1893193")
// returns '1,9 miljarder'
largeNumber("1893193000")
// returns '1 893 miljoner'
largeNumber("1893000000", {magnitude: 6})

ja

// returns '1.2億'
largeNumber("123456789")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
magnitude number <optional>
Force the output to be in e.g. millions
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) largeNumberChange(val, optsopt) → {string}

Description:
  • Print large numbers using affixes like “million”
Examples

sv

// returns '+1,9 miljoner'
largeNumberChange("1893193")
// returns '+1,9 miljarder'
largeNumberChange("1893193000")
// returns '+1 893 miljoner'
largeNumberChange("1893000000", {magnitude: 6})

ja

// returns '+1.2億'
largeNumberChange("123456789")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
magnitude number <optional>
Force the output to be in e.g. millions
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) largeNumberChangeShort(val, optsopt) → {string}

Description:
  • Print large numbers using affixes like “mil.”
Examples

sv

// returns '+1,9 mn'
largeNumberChange("1893193")
// returns '+1,9 md'
largeNumberChange("1893193000")
// returns '+1 893 mn'
largeNumberChange("1893000000", {magnitude: 6})

ja

// returns '+1.2億'
largeNumberChange("123456789")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
magnitude number <optional>
Force the output to be in e.g. millions
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) largeNumberPretty(val, optsopt) → {string}

Description:
  • Print large numbers using affixes like “million”
Example

sv

// returns 'en miljon'
largeNumberPretty("1093193")
// returns '19 miljoner'
largeNumberPretty("19093193")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
magnitude number <optional>
Number of zeroes, e.g. 6 for millions
gender string <optional>
"neuter" Gender, in languages where it matters
numberSystem string <optional>
Number system, if non default for this locale
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
Returns:
Textual representation
Type
string

(static) largeNumberShort(val, optsopt) → {string}

Description:
  • Print large numbers using short affixes like “mil.”
Examples

sv

// returns '1,9 mn'
largeNumber("1893193")
// returns '1,9 md'
largeNumber("1893193000")
// returns '1 893 mn'
largeNumber("1893000000", {magnitude: 6})

ja

// returns '1.2億'
largeNumber("123456789")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
magnitude number <optional>
Force the output to be in e.g. millions
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) largeNumberText(val, optsopt) → {string}

Description:
  • Print large numbers using affixes like “million”. Note that in some languages the number if gendered by the item counted, whereas in other languages (like Swedish) it is gendered by the affix itself. The gender option is for the former case only, and will not have any effect in e.g. Swedish (where ”ett miljon” is never used).
Example

sv

// returns 'En miljon'
largeNumberText("1093193")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
magnitude number <optional>
Number of zeroes, e.g. 6 for millions
gender string <optional>
"neuter" Gender, in languages where it matters
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
Returns:
Textual representation
Type
string

(static) millions(val, optsopt) → {string}

Description:
  • Print large numbers as a number of millions.
    This is an alias for largeNumber(val, {magnitude: 6})
Example

sv

// returns '1,9 miljoner'
millions("1893193")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) millionsChange(val, optsopt) → {string}

Description:
  • Print large numbers as a number of millions.
    This is an alias for largeNumberChange(val, {magnitude: 6})
Example

sv

// returns '+1,9 miljoner'
millionsChange("1893193")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) millionsChangeShort(val, optsopt) → {string}

Description:
  • Print large numbers as a number of millions.
    This is an alias for largeNumberChangeShort(val, {magnitude: 6})
Example

sv

// returns '+1,9 mn'
millionsChangeShort("1893193")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) millionsPretty(val, optsopt) → {string}

Description:
  • Print large numbers as a number of millions.
Example

sv

// returns 'två miljoner'
millionsPretty("2_000_000")
// returns '2,1 miljoner'
millionsPretty("2_100_000")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Returns:
Textual representation
Type
string

(static) millionsShort(val, optsopt) → {string}

Description:
  • Print large numbers as a number of millions.
    This is an alias for largeNumberShort(val, {magnitude: 6})
Example

sv

// returns '1,9 mn'
millionsShort("1893193")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem number <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) millionsText(val, optsopt) → {string}

Description:
  • Print large numbers as a number of millions.
    This is an alias for largeNumber(val, {magnitude: 6})
Example

sv

// returns 'två miljoner'
millionsText("2_000_000")
Parameters:
Name Type Attributes Description
val number A number to represent
opts object <optional>
Options
Returns:
Textual representation
Type
string

(static) multiplier(val, str, optsopt) → {string}

Description:
  • Describe a multiplier like ”three times as many”, using a generic phrase
Example

sv

// returns '3 gånger så mycket'
multiplier("3", "mycket")
Parameters:
Name Type Attributes Description
val number A multiplier
str string A this to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
gender string <optional>
"neuter" Gender, in languages where it matters
numberSystem string <optional>
Number system, if non default for this locale
denominator number <optional>
Keep the denominator below this in fractions
forceDenominator boolean <optional>
Force the denominator to given value in fractions
Returns:
Textual representation
Type
string

(static) multiplierPretty(val, str, optsopt) → {string}

Description:
  • Describe a multiplier like ”three times as many”, using a generic phrase
Example

sv

// returns 'tre gånger så mycket'
multiplierPretty("3", "mycket")
Parameters:
Name Type Attributes Description
val number A multiplier
str string A this to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
gender string <optional>
"neuter" Gender, in languages where it matters
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
numberSystem string <optional>
Number system, if non default for this locale
Returns:
Textual representation
Type
string

(static) multiplierText(val, str, optsopt) → {string}

Description:
  • Describe a multiplier like ”three times as many”, using a generic phrase
Example

sv

// returns 'tre gånger så mycket'
multiplierText("3", "mycket")
Parameters:
Name Type Attributes Description
val number A multiplier
str string A this to represent
opts object <optional>
Options
Properties
Name Type Attributes Default Description
gender string <optional>
"neuter" Gender, in languages where it matters
Returns:
Textual representation
Type
string

(static) number(val, optsopt) → {string}

Description:
  • Basic number formating, using the default number format for a locale, and the default number system.
Examples

sv

// returns '1 234,5'
number(1234.5)
// returns 'XIV'
number(14, {numberSystem: "roman"})

en

// returns '1,234.5'
number(1234.5)
// returns '1,235'
number(1234.5, {decimalDigits: 0})

ar

// returns '١٬٢٣٤٫٥'
number(1234.5)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
precision number <optional>
A indicative number to round to, e.g. 1_000
significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
A textual representation
Type
string

(static) numberPretty(val, optsopt) → {string}

Description:
  • Spell out low numbers, use numerical representation for higher numbers, if that is preferred in this language
Example

sv

// returns 'ett'
numberPretty(1)
// returns '19'
numberPretty(19)
// returns 'nitton'
numberPretty(19, {prettyLimit: 20})
Parameters:
Name Type Attributes Description
val number A number
opts object <optional>
Options
Properties
Name Type Attributes Default Description
gender string <optional>
"neuter" Gender, in languages where it matters
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0? This is only applied to numerical output
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
A textual representation
Type
string

(static) numberText(val, optsopt) → {string}

Description:
  • Textual representation of a number
Examples

de

//returns 'Zwei'
numberText(2)

en

//returns 'twentyfour'
numberText(24)
//returns 'twentyfour point one'
numberText(24.123)
Parameters:
Name Type Attributes Description
val number A number to print out
opts object <optional>
Options
Properties
Name Type Attributes Default Description
gender string <optional>
"neuter" Gender, in languages where it matters
decimalDigits number <optional>
1 Number of fraction digits to show
Returns:
A textual representation
Type
string

(static) ordinal(number, optsopt) → {string}

Description:
  • Numeric ordinals, e.g. '1st', '1:a', etc
Examples

sv

// returns '1:a'
ordinal(1)
// returns '1:e'
ordinal(1, {gender: "masculine"})

nb

// returns '1.'
ordinal(1)
Parameters:
Name Type Attributes Description
number number A cardinal number
opts object <optional>
Options
Properties
Name Type Attributes Default Description
gender string <optional>
"neuter" Gender, in languages where it matters
Returns:
A textual representation
Type
string

(static) ordinalAdverb(number, adverb, optsopt) → {string}

Description:
  • Create an adjectival or adverbial numerical ordinal, e.g. 2.größte” (de).
    For many languages, this will be more os less the same as `${ordinal(number)} ${adverb}`.
Examples

sv

// returns 'största'
ordinalAdverb(1, "största")
// returns '10:e största'
ordinalAdverb(10, "största")

de

// returns '2.größte'
ordinalAdverb(2, "größte")
Parameters:
Name Type Attributes Description
number number A cardinal number
adverb string An adjective/adverb
opts object <optional>
Options
Properties
Name Type Attributes Description
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
A adverbial compound or similar
Type
string

(static) ordinalAdverbPretty(val, adverb, optsopt) → {string}

Description:
  • Create an adjectival or adverbial ordinal, e.g. zweitgrößte” (de), using textual or numerical ordinals depending on number.
Examples

sv

// returns 'största'
ordinalAdverbPretty(1, "största")
// returns 'näst största'
ordinalAdverbPretty(2, "största")
// returns '20:e största'
ordinalAdverbPretty(20, "största")

de

// returns 'zweitgrößte'
ordinalAdverbPretty(2, "größte")
// returns '100.größte'
ordinalAdverbPretty(100, "größte")
Parameters:
Name Type Attributes Description
val number A cardinal number
adverb string An adjective/adverb
opts object <optional>
Options
Properties
Name Type Attributes Description
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
prettyLimit number <optional>
What number should be large enough for numerical ordinals?
Returns:
A adverbial compound or similar
Type
string

(static) ordinalAdverbText(number, adverb, optsopt) → {string}

Description:
  • Create an adjectival or adverbial texual ordinal, e.g. zweitgrößte” (de).
    For many languages, this will be more os less the same as `${ordinalText(number)} ${adverb}`.
Examples

sv

// returns 'största'
ordinalAdverb(1, "största")
// returns 'näst största'
ordinalAdverb(2, "största")
// returns 'tionde största'
ordinalAdverb(10, "största")

de

// returns 'zweitgrößte'
ordinalAdverb(2, "größte")
// returns 'hundertgrößte'
ordinalAdverb(100, "größte")
Parameters:
Name Type Attributes Description
number number A cardinal number
adverb string An adjective/adverb
opts object <optional>
Options
Properties
Name Type Attributes Description
numberSystem string <optional>
What number system should we use? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
A adverbial compound or similar
Type
string

(static) ordinalPretty(val, optsopt) → {string}

Description:
  • Spell out ordinals for low numbers, use numerical represenation for higher numbers, if that is preferred in this language
Example

sv

// returns 'första'
ordinalPretty(1)
// returns '19:e'
ordinalPretty(19)
// returns 'nittonde'
ordinalPretty(19, {prettyLimit: 20})
Parameters:
Name Type Attributes Description
val number A cardinal number
opts object <optional>
Options
Properties
Name Type Attributes Default Description
gender string <optional>
"neuter" Gender, in languages where it matters
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
Returns:
A textual representation
Type
string

(static) ordinalText(number, optsopt) → {string}

Description:
  • Textual ordinals, e.g. 'first', 'första', 'erste', etc
Examples

sv

// returns 'första'
ordinalText(1)
// returns 'förste'
ordinalText(1, {gender: "masculine"})

nb

// returns 'første'
ordinalText(1)
Parameters:
Name Type Attributes Description
number number A cardinal number
opts object <optional>
Options
Properties
Name Type Attributes Default Description
gender string <optional>
"neuter" Gender, in languages where it matters
Returns:
A textual representation
Type
string

(static) percent(val, optsopt) → {string}

Description:
  • Format percent. This is the same as number(n * 100)
Examples

sv

// returns '15,1'
percent(0.151)

en

// returns '15.1'
percent(0.151)
// returns '15'
percent(0.151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) percentInteger(val, optsopt) → {string}

Description:
  • Format percent. This is roughly the same as integer(n * 100)
Examples

sv

// returns '15'
percentInteger(0.151)

en

// returns '15'
percentInteger(0.151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) percentIntegerPretty(val, optsopt) → {string}

Description:
  • Format percent. This is roughly the same as integerPretty(n * 100)
Example

sv

// returns '15'
percentIntegerPretty(0.151)
// returns 'elva'
percentIntegerText(0.111)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) percentIntegerText(val, optsopt) → {string}

Description:
  • Format percent. This is roughly the same as integerText(n * 100)
Examples

sv

// returns 'femton'
percentIntegerText(0.151)

en

// returns 'fifteen'
percentIntegerText(0.151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) percentLong(val, optsopt) → {string}

Description:
  • Format a full percent string, like "15 percent"
Examples

sv

// returns '15,1 procent'
percentLong(0.151)

en

// returns '15.1 percent'
percentLong(0.151)

// returns '15 percent'
percentLong(0.151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts Options <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) percentLongInteger(val, optsopt) → {string}

Description:
  • Format a full percent string, like "15 percent"
Examples

sv

// returns '15 procent'
percentLongInteger(0.151)

en

// returns '15 percent'
percentLongInteger(0.151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) percentLongIntegerPretty(val, optsopt) → {string}

Description:
  • Format a long percent string, like "15 percent"
Example

sv

// returns '15 procent'
percentLongIntegerPretty(0.151)
// returns 'elva procent'
percentLongIntegerPretty(0.111)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) percentLongIntegerText(val, optsopt) → {string}

Description:
  • Format a long percent string, like "fifteen percent"
Examples

sv

// returns 'en procent'
percentLongIntegerText(0.01)

en

// returns 'fifteen percent'
percentLongIntegerText(0.151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
gender string <optional>
Note that grammatical gender may be overriden as the word percent itself has a gender in e.g. Swedish
Returns:
A textual representation
Type
string

(static) percentLongPretty(val, optsopt) → {string}

Description:
  • Format a long percent string, like "fifteen percent"
Example

sv

// returns '15,1 procent'
percentLongPretty(0.151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) percentLongText(val, optsopt) → {string}

Description:
  • Format a long percent string, like "fifteen percent"
Example

sv

// returns 'femton komma en procent'
percentLongText(0.151)
// returns 'femton procent'
percentLongText(0.151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
Returns:
A textual representation
Type
string

(static) percentPretty(val, optsopt) → {string}

Description:
  • Format percent. This is roughly same as numberPretty(n * 100) but with support for gendered grammars.
Example

sv

// returns '15,1'
percentPretty(0.151)
// returns 'tre'
percentPretty(0.03)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) percentShort(val, optsopt) → {string}

Description:
  • Format a short percent string, for use in tables and similar
Examples

sv

// returns '15,1 %'
percentShort(0.151)

en

// returns '15.1 %'
percent(0.151)
// returns '15 %'
percent(0.151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts Options <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) percentShortInteger(val, optsopt) → {string}

Description:
  • Format a short percent string, for use in tables and similar
Example

sv

// returns '15 %'
percentShortInteger(0.151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) percentText(val, optsopt) → {string}

Description:
  • Format percent. This is roughly same as numberText(n * 100) but with support for gendered grammars.
Example

sv

// returns 'femton komma en'
percentText(0.151)
// returns 'femton'
percentText(0.151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
Returns:
A textual representation
Type
string

(static) permille(val, optsopt) → {string}

Description:
  • Format per mille. This is the same as number(n * 1000)
Example

sv

// returns '151'
permille(0.151)

// returns '15,1'
permille(0.0151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
opt.precision number <optional>
A indicative number to round to, e.g. 1_000
opt.significantDigits number <optional>
A number of significant digits to show, e.g. 3
Returns:
A textual representation
Type
string

(static) permilleInteger(val, optsopt) → {string}

Description:
  • Format per mille. This is roughly the same as integer(n * 1000)
Examples

sv

// returns '15'
permilleInteger(0.0151)

en

// returns '15'
permilleInteger(0.0151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) permilleIntegerPretty(val, optsopt) → {string}

Description:
  • Format per mille. This is roughly the same as integerPretty(n * 1000)
Example

sv

// returns '15'
permilleIntegerPretty(0.0151)
// returns 'elva'
permilleIntegerPretty(0.0111)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) permilleIntegerText(val, optsopt) → {string}

Description:
  • Format permille. This is roughly the same as integerText(n * 1000)
Examples

sv

// returns 'femton'
permilleIntegerText(0.0151)

en

// returns 'fifteen'
permilleIntegerText(0.0151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
gender string <optional>
Note that grammatical gender may be overriden as the word permille itself has a gender in e.g. Swedish
Returns:
A textual representation
Type
string

(static) permilleLong(val, optsopt) → {string}

Description:
  • Format a full per mille string, like "15 per mille"
Examples

sv

// returns '15,1 promille'
permilleLong(0.0151)

en

// returns '15.1 per mille'
permilleLong(0.151)

// returns '15 per mille'
permilleLong(0.151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts Options <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) permilleLongInteger(val, optsopt) → {string}

Description:
  • Format a full per mille string, like "15 promille"
Examples

sv

// returns '15 promille'
permilleLongInteger(0.0151)

en

// returns '15 per mille'
permilleLongInteger(0.0151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) permilleLongIntegerPretty(val, optsopt) → {string}

Description:
  • Format a long per mille string, like "15 per mille"
Example

sv

// returns '15 promille'
permilleLongIntegerPretty(0.0151)
// returns 'elva promille'
permilleLongIntegerPretty(0.0111)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) permilleLongIntegerText(val, optsopt) → {string}

Description:
  • Format a long percent string, like "fifteen percent"
Example

sv

// returns 'en promille'
permilleLongIntegerText(0.001)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
gender string <optional>
Note that grammatical gender may be overriden as the word permille itself has a gender in e.g. Swedish
Returns:
A textual representation
Type
string

(static) permilleLongPretty(val, optsopt) → {string}

Description:
  • Format a long per mille string, like "fifteen per mille"
Example

sv

// returns '15,1 promille'
permilleLongPretty(0.0151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) permilleLongText(val, optsopt) → {string}

Description:
  • Format a long per mille string, like "fifteen per mille"
Example

sv

// returns 'femton komma en promiolle'
permilleLongText(0.0151)
// returns 'femton promille'
permilleLongText(0.0151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
Returns:
A textual representation
Type
string

(static) permillePretty(val, optsopt) → {string}

Description:
  • Format permille. This is roughly same as numberPretty(n * 1000) but with support for gendered grammars.
Example

sv

// returns '15,1'
permillePretty(0.0151)
// returns 'tre'
permillePretty(0.003)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
prettyLimit number <optional>
Below what limit do we spell-out numbers? A language specific default will be used if none given.
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) permilleShort(val, optsopt) → {string}

Description:
  • Format a short per mille string, for use in tables and similar
Examples

sv

// returns '15,1 ‰'
permilleShort(0.0151)

en

// returns '15.1 ‰'
permilleShort(0.0151)

// returns '15 ‰'
permilleShort(0.0151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts Options <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
forceDecimalDigits boolean <optional>
false Show decimal digits even if they are 0
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) permilleShortInteger(val, optsopt) → {string}

Description:
  • Format a short permille string, for use in tables and similar
Example

sv

// returns '15 ‰'
permilleShortInteger(0.0151)
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
numberSystem string <optional>
Number system to use, if non standard
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
Returns:
A textual representation
Type
string

(static) permilleText(val, optsopt) → {string}

Description:
  • Format permille. This is roughly same as numberText(n * 1000) but with support for gendered grammars.
Example

sv

// returns 'femton komma en'
permilleText(0.0151)
// returns 'femton'
permilleText(0.0151, {decimalDigits: 0})
Parameters:
Name Type Attributes Description
val number A number to format
opts object <optional>
Options
Properties
Name Type Attributes Default Description
decimalDigits number <optional>
1 Number of fraction digits to show
Returns:
A textual representation
Type
string

(static) sign(number, optsopt) → {string}

Description:
  • Get a plus or minus sign for a value.
    This is intended for displaying changes or differences.
    See also: change
Examples

sv

let diff1 = 6.2
let diff2 = -6.2
// returns +6,2
sign(diff) + number(diff)
// returns −6,2
sign(diff2) + number(diff2)

ar

// returns -6,2
sign(diff2) + number(diff2)
Parameters:
Name Type Attributes Description
number number A numerical value
opts object <optional>
Options
Properties
Name Type Attributes Default Description
zeroSign number <optional>
0 What sign should the number 0 have? 1, -1 or 0
numberSystem string <optional>
What number system should we use to get the plus/minus signs? Defaults to the standard for decimal numbers in the current locale, e.g. 'latn' or 'arab'.
Returns:
An affix, e.g. "+" or "-"
Type
string

(static) unit(val, unit, optsopt) → {string}

Description:
  • Format a number with a unit, e.g. "massKilogram" For list of common units, see http://www.unicode.org/reports/tr35/tr35-general.html#perUnitPatterns or for the full list: http://unicode.org/repos/cldr/tags/latest/common/validity/unit.xml
Examples

en

// returns '3 millimetres'
unit(3, "lengthMillimeter")

zh

// returns '3毫米'
unit(3, "lengthMillimeter")
Parameters:
Name Type Attributes Description
val number A numerical value
unit string A CLDR unit code
opts object <optional>
Options
Properties
Name Type Attributes Description
numberSystem string <optional>
Number system to use, if non standard
Returns:
A formatted measure
Type
string

(static) unitShort(val, unit, optsopt) → {string}

Description:
Examples

en

//returns '3 mm'
unitShort(3, "lengthMillimeter")

zh

//returns '3毫米'
unitShort(3, "lengthMillimeter")
Parameters:
Name Type Attributes Description
val number A numerical value
unit string A CLDR unit code
opts object <optional>
Options
Properties
Name Type Attributes Description
numberSystem string <optional>
Number system to use, if non standard
Returns:
A formatted measure
Type
string