3.12.1Framework.FormatNumber()

FormatNumber() is a general-purpose function for formatting numbers. It has two parameters: the number to convert, and a block of options. For example:

var text = Framework.FormatNumber(1234.5678, {digits: 3, show_plus: true})

// With standard settings, returns "+1,234.568"

Option property

Description

digits

Number of decimal places to include (with rounding). Defaults to 2 if neither digits nor max_digits is specified

max_digits

Allows a variable number of decimal places, as required, up to a maximum of max_digits. For example, if max_digits=2 then the results of the formatting will be as follows:

123 = "123"

123.1 = "123.1"

123.456 = "123.46"

roundUp001

Designed for use with percentages where, even if the rounding is mathematically accurate, you don't want to display a value as 0.0 or 100.0 unless it is exactly 0 or 100. If roundUp001 true and digits>0, value which would be rounded down to 0 or up to 100 will instead be displayed as the minimum "increment" such as 0.01 or 99.99

thousands

Display numbers in millions or thousands as xM or xK, with the fractional amount of thousands/millions controlled by digits or max_digits. For example, with {thousands: true, max_digits: 1}:

1456 = "1.5K"

1000000 = "1M"

show_plus

Add a + as a prefix to positive numbers, typically used in relation to profit/loss amounts, or percentages which can be either positive or negative

zero

If the number is exactly zero, and options.zero is not null, then the function returns the value of options.zero - for example, an empty string, or a placeholder such as -

thousands_separator

Automatically set based on user's choice of language/region

decimal_separator

Automatically set based on user's choice of language/region

prefix

Any prefix (such as a currency symbol) to add to the start of the text

suffix

Any suffix to add to the end of the text