SAPUI5 - Localization of Number Format

I have a problem with formatting numbers for decimal places in different languages. For the CURRENCY control, the system accepts the correct format based on the language coming from the URL parameter; USA and DE ?sap-ui-language=DE or?sap-ui-language=US

For input fields that have an attribute type=Number, it always uses DOT as a decimal separator, regardless of language. Is there a solution to this problem? I have a dynamic sap.ui.table populated (for both rows and columns), and some rows have numeric fields and some rows as text fields, so I dynamically send data from the database, as shown below:

temp = new sap.m.Input(sColumnId + index,{  value:"{path: '" + sColumnId + "'}" , type:"{DATATYPE}",  textAlign:"Right", liveChange:[handle_livechange,this], change:[handle_change, this] , editable:"{path:'EDITABLE', type:'sap.ui.model.odata.type.String'}" }

since some lines are text based, I cannot format the hard code as shown below:

 type:'sap.ui.model.type.Float', formatOptions : {   groupingEnabled: true, groupingSeparator: '.', decimalSeparator : ',', minFractionDigits: 2}}"

I tried a custom formatter, but somehow on a dynamic table my formatting function could not be found. I tried the onChange method for dynamic formatting, but in this case my javascript calculations do not work.

If I can control the formatting option based on the string value with the expression binding, it will also fix my problem, but the code below does not work.

temp = new sap.m.Input(sColumnId + index,{  value:"{path: '" + sColumnId + ", =${DATATYPE} === 'Number' ? type:'sap.ui.model.type.Float', formatOptions : {   groupingEnabled: true, groupingSeparator: '.', decimalSeparator : ',', minFractionDigits: 2} : type:'sap.ui.model.type.String' }"
+4
source share
1 answer

This approach works for me: define a locale-based format, for example, in a format file:

        sap.ui.define([
            "sap/ui/core/format/NumberFormat"
        ], function (NumberFormat) {     
        var oFloatNumberFormat = NumberFormat.getFloatInstance({
                    maxFractionDigits: 2,
                    minFractionDigits : 2,
                    groupingEnabled: true
                } , sap.ui.getCore().getConfiguration().getLocale());
        }


        return {
                 floatFormat: function(value){
                 return oFloatNumberFormat.format(value);
            },
    }
});

now where do you want to use it:

var MyVar= new sap.m.Input({
            value: {
                path: "..../amount" ,
                formatter : function(amount) {
                    return yourdefinedname.floatFormat(amount);
                }
             }
          });
+2
source

Source: https://habr.com/ru/post/1680023/


All Articles