Code_Tech
Code_Tech

Reputation: 795

How to incorporate different number representation depending on user locale in UI5?

For the SAPUI5 app, I want to display number data, according to settings set by user in SU01 (backend transaction, in SAP Logon).

For example, user can set decimal separators as

  1. 22,000.000 (twenty two thousand) → US format
  2. 22.000,000 (twenty two thousand) → German format

Based on these settings, the UI5 app should know which decimal format has been used, and format the data accordingly.

I am trying to follow the topic Number Format, but the issue here is, I need to manually provide region. Ideally, I want to find it from user settings.

var oLocale = new sap.ui.core.Locale("en-US");
var oFormatOptions = {
  showMeasure: true
};

Upvotes: 1

Views: 916

Answers (1)

Boghyon Hoffmann
Boghyon Hoffmann

Reputation: 18064

Most of the time, app developers don't have to determine the locale explicitly as UI5 already tries to identify the user locale for the app according to the heuristic mentioned in the topic Identifying the Language Code / Locale (See the section "Current Language Code / Locale").

Given the OData property "Freight": "22000" (typed Edm.Decimal), the following sample shows that users can enter the value in their locale format without the app having to determine the locale manually: https://embed.plnkr.co/b32woxbQmdj5dTRu?show=view/Root.view.xml,preview:?sap-ui-xx-componentPreload=off

If the user has e.g. "English (United States)" moved to the top in the browser setting:
OData V2 Edm.Decimal in UI5 English

If "German (Germany)" is moved to the top:
OData V2 Edm.Decimal in UI5 German

Upvotes: 1

Related Questions