Skip to main content

Number Formatting

Dromo's number field type comes with many useful presets out of the box. If none of the presets meet your needs, you can specify your own format.

Number format configuration

Dromo uses the Numbro library under the hood for number parsing and formatting. The displayFormat and outputFormat parameters accept objects with valid Numbro format options.

Rounding

Separate from the display and output formats, Dromo accepts a round option. Rounding takes place at the time input is received and parsed into the canonical value.

The round option takes an integer, equal to the number of digits after the decimal point to round to. Here is an example of some round values, given the input value 8888.888:

roundValue
28888.89
18888.9
08889
-18890
-28900

Output format

If no outputFormat is specified, Dromo outputs number fields as ordinary JSON numbers. These are the raw underlying value of the field, so for example the displayed value "12%" would be output as 0.12.

If you specify an outputFormat, Dromo will instead output the number as a string in the specified format.

Precision

During the import process, numbers in number fields are stored as standard JavaScript numbers, which are double-precision IEEE 754 floating point numbers. This imposes limits on how large and how precise a number can be.

The maximum integer which can be handled is 2^53 - 1, or 9007199254740991. The minimum integer is -(2^53 - 1), or -9007199254740991.

Preset reference

Here are the equivalent settings for each of the presets provided by Dromo.

default

{
displayFormat: {
thousandSeparated: true
}
}

percent

{
displayFormat: {
output: "percent"
}
}

percent_0

{
round: 2,
displayFormat: {
output: "percent",
mantissa: 0
}
}

percent_1

{
round: 3,
displayFormat: {
output: "percent",
mantissa: 1
}
}

percent_2

{
round: 4,
displayFormat: {
output: "percent",
mantissa: 2
}
}

percent_3

{
round: 5,
displayFormat: {
output: "percent",
mantissa: 3
}
}

percent_4

{
round: 6,
displayFormat: {
output: "percent",
mantissa: 4
}
}

decimal_0

{
round: 0,
displayFormat: {
thousandSeparated: true,
mantissa: 0
}
}

decimal_1

{
round: 1,
displayFormat: {
thousandSeparated: true,
mantissa: 1
}
}

decimal_2

{
round: 2,
displayFormat: {
thousandSeparated: true,
mantissa: 2
}
}

decimal_3

{
round: 3,
displayFormat: {
thousandSeparated: true,
mantissa: 3
}
}

decimal_4

{
round: 4,
displayFormat: {
thousandSeparated: true,
mantissa: 4
}
}

plain

{}

usd

{
round: 2,
displayFormat: {
mantissa: 2,
thousandSeparated: true,
output: "currency",
average: false,
spaceSeparatedCurrency: true,
currencyPosition: "prefix",
currencySymbol: "$"
}
}

usd_accounting

{
round: 2,
displayFormat: {
mantissa: 2,
thousandSeparated: true,
output: "currency",
average: false,
spaceSeparatedCurrency: true,
currencyPosition: "prefix",
currencySymbol: "$",
negative: "parenthesis"
}
}

eur

{
round: 2,
displayFormat: {
mantissa: 2,
thousandSeparated: true,
output: "currency",
average: false,
spaceSeparatedCurrency: true,
currencyPosition: "postfix",
currencySymbol: "€"
}
}

gbp

{
round: 2,
displayFormat: {
mantissa: 2,
thousandSeparated: true,
output: "currency",
average: false,
spaceSeparatedCurrency: true,
currencyPosition: "prefix",
currencySymbol: "£"
}
}