Formatting Numbers
sap.ui.core.format.NumberFormat
Intro
This article describes the international rules for number formats. The SAPUI5 number formatters will help you to comply with these rules.
Usage
Use number formatting if:
- You need to display numbers based on the user’s locale settings.
Do not use number formatting if:
- You need to display IDs.
- You need to display telephone numbers.
Types
You can use three different datatypes for numbers: integer, float, and currency. Each datatype can be formatted using a short, standard, or long format.
Integer
Use integer if no decimal places are required.
Short
Standard
Formatting numbers - Standard
Long
Integer (long)
Float
If you want to show decimal places, use float. The decimal places beyond the defined number of digits are truncated. If the minimum number of decimal digits is not restricted, only the trailing zeros are truncated, which could lead to very large numbers.
Short
Float number - Short
Standard
Float number - Standard
Long
Float number - Long
Currency
Example of Tunisian dinar with three decimal places
Short
Currency amounts that are greater than 1,000 and use the short format are abbreviated.
Currency - Short
Standard
In general, use the standard format. Numbers using the standard format are displayed in full, including the decimal places.
Example of a formatted currency amount - Standard
Long
Use the long format to show units as full text, such as thousand, million, and so on.
Currency (long)
Guidelines
- In general, use the standard format.
- Follow the rules of the corresponding control to format the data appropriately. (For example, show 1.7M instead of 1,700,000 in the object list item.)
- Use float numbers to prevent truncation of decimal places.
- If you need to display amount fields without a value, leave them blank. Do not display a text as N/A.
- Always use the correct format according to your language or locale setting to prevent confusion caused by incorrect formatting. (For example, “200,000” is interpreted as “two hundred thousand” in the United States, but “two hundred point zero” in Germany.)
- If you need to display decimal numbers, use float and keep the number of digits after the decimal point to a minimum.
- Use object numbers where possible, for example, to display amounts in forms and responsive tables.
Resources
Want to dive deeper? Follow the links below to find out more about related controls, the SAPUI5 implementation, and the visual design.
Elements and Controls
- Object Number (guidelines)
- Responsive Table (guidelines)
Implementation
- Number Format (SAPUI5 API reference)
Visual Design
- No links