Number input
When entering numbers, it's best to support these formats and ignore nonsensical characters instead of generating errors. No thousand separators are used.
Description |
Comments |
🇬🇧 |
🇩🇰 |
🇳🇱 |
🇫🇮 |
🇳🇴 |
🇸🇪 |
---|---|---|---|---|---|---|---|
Decimal separators |
The U.K. and the U.S. are two of the few countries in the world that use a period to indicate the decimal place. Many other countries use a comma instead. |
(.) |
(,)
|
(,)
|
(,)
|
(,)
|
(,)
|
Decimal separator examples |
|
350.00
|
350,00 |
350,00 |
350,00 |
350,00 |
350,00 |
Percentage |
Percentages can be expressed in various formats such as 95%, 95 %, 95 pct, 0.95, and %95. Therefore, it is not safe to assume that the percent sign will always be used consistently. |
95% 95 % (non-breaking) or
space |
95 %
(spc) |
95 %
(spc) |
95 %
(spc) |
95 %
(spc) |
95 %
(spc) |
Number display
Standard format by country:
- Use an official decimal separator
- Use the standard number of decimals and 0 added if needed
- Use thousand separators for read-only numbers
- Use non-breaking space for thousands in whole numbers (not a comma)
- Group decimals in a single block: 152 231.324567
Description |
Comments |
🇬🇧 |
🇩🇰 |
🇳🇱 |
🇫🇮 |
🇳🇴 |
🇸🇪 |
---|---|---|---|---|---|---|---|
Thousand separators group digits of large numbers into three-digit groups, making it easy to estimate their order of magnitude in thousands, millions, billions, or other large units at a glance. |
The UK and US use commas to separate groups of thousands, while other countries use periods or thin spaces. |
(.) (,) (thin space) |
(,) (space) (thin space) |
(,) (space) (thin space) |
(,) (space) (thin space) |
(.) (,) (thin space) |
(,) (space) (thin space) |
Decimal separator examples |
|
350,00 |
350,00 |
350,00 |
350,00 |
350,00 |
350,00 |
Large number |
|
4,294,967,295.00
|
4 294 967 295,000
|
4 294 967 295,00
|
4 294 967 295,000
|
4.294.967.295,000
|
4 294 967 295,000
|
Percentage |
When writing numbers and percentage signs, English style guides recommend omitting any space between them.
However, the International System of Units and ISO 31-0 standard recommend including a space, which is consistent with the common practice of using a non-breaking space between a numerical value and its corresponding unit of measurement. |
95% 95 %
(non-breaking) or (space)
|
95 %
(space) |
95 %
(space) |
95 %
(space) |
95 %
(space) |
95 %
(space) |
Number format
- All spaces are stripped from the input
- One of either (.) or (,) is fine
- More than one of (,) or (.) triggers a validation error
- Any number before (,) or (.) is treated as the whole number
- Any number after , or . is treated as the decimal value
- (,) or (.) are optional
- If there is no value for the decimal part, the decimal value is 0 (e.g. 1. or 1 are both 1.00)
- Minus signs must be the first character if used, and triggers an error otherwise
- Plus signs must be the first character if used, and triggers an error otherwise
- The only allowed characters are (0-9) (,) (.) (+) (-) or (space)
- Using any other characters triggers an error
A few recommended test cases to try when working with numerical inputs
- 1 -> 1.0
- 1.0 -> 1.0
- 1,0 -> 1.0
- 1000 -> 1,000.00
- 1000.0 -> 1,000.00
- 1000,0 -> 10,000.00
- 1,000 -> 1,000.00
- 1.000 -> 1.000
- 1 000 -> 1,000.00
- 1,000.0 -> 1,000.00
- 1.000,0 -> 1.0000
- 1 000.0 -> 1,000.00
- 1 000,0 -> 10,000.00
The following numbers should result in an error
- 1.000,0 -> error
- 1,.0 -> error
- 1,,0 -> error
- 1..0 -> error
- 1.,0 -> error
Other border cases
- 0 -> 0 Expected: 0.00
- 0,0 -> 0,0 Expected: 0.00
- ,1 -> ,1 Expected format of type n.nn
- .1 -> .1 Expected format of type n.nn, triggers validation error when saving
- 1,,0 -> 1,0.00 Expected: error
- 1..0 -> 1.00 Expected: error
- 1,0,0.0 -> 10,0.00
- 1 0 0.0 -> 1 0 0.00 Triggers validation error
- 1(space) -> 1 .00 Triggers validation error
- 1,(space) -> 1 .00 Triggers validation error, 1.(space) works as expected
- 1e2 -> 1e2.00 Triggers validation error
- 1.e2 -> 1.e2 Saved as 100.00, also
- 1.0e2 -> 1.0e2 Saved as 100.00
- 1.0e-2 -> 1.0e2 Minus sign is silently stripped, same behaviour for e.g. 1000.0e-2
- 1.0e+2 -> 1.0e2 Plus sign is silently stripped, expected error
- 1.0e7 -> 1.0e7 Doesn't trigger validation error, 10 000 000.00 can't be saved when edited