admin管理员组

文章数量:1314504

I have an issue related to number formatting for decimals in different languages. For the CURRENCY control, system takes the correct format based on the language ing from the URL parameter; US and DE ?sap-ui-language=DE or ?sap-ui-language=US

For the input fields which has type=Number attribute, always uses DOT as decimal separator regardless of language setting. Is there a solution for this problem ? I have a dynamic sap.ui.table populated (for both rows and columns) and some rows has number fields and some rows as text fields so i am sending dataformat from the backend dynamically as 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 rows are text based, i cannot hard code formatter as below;

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

I tried custom formatter but somehow on dynamic table my formatter function cannot be found. I tried onChange method to dynamically format but in this case my javascript calculations doesnt work.

If i can control the formatting option based on the row value with expression binding, it will also fix my issue but below code doesn't 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' }"

I have an issue related to number formatting for decimals in different languages. For the CURRENCY control, system takes the correct format based on the language ing from the URL parameter; US and DE ?sap-ui-language=DE or ?sap-ui-language=US

For the input fields which has type=Number attribute, always uses DOT as decimal separator regardless of language setting. Is there a solution for this problem ? I have a dynamic sap.ui.table populated (for both rows and columns) and some rows has number fields and some rows as text fields so i am sending dataformat from the backend dynamically as 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 rows are text based, i cannot hard code formatter as below;

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

I tried custom formatter but somehow on dynamic table my formatter function cannot be found. I tried onChange method to dynamically format but in this case my javascript calculations doesnt work.

If i can control the formatting option based on the row value with expression binding, it will also fix my issue but below code doesn't 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' }"
Share Improve this question asked Jun 24, 2017 at 14:51 bilenbilen 1451 gold badge2 silver badges10 bronze badges 6
  • Which values backend can return in {DATATYPE} property? – Andrew Naumovich Commented Jun 24, 2017 at 18:44
  • It is eithet Number or Text . Both formatting working fine but when it is Number, system making decimal seperator as DOT regardless of language setting – bilen Commented Jun 26, 2017 at 0:31
  • Why don't you use it simplier, like this: <Input editable="{EDITABLE}" value="{ path: 'property/value', type: 'sap.ui.model.type.Float'}"/> ? This should automatically take the locale settings to build the correct separators. – Andrew Naumovich Commented Jun 26, 2017 at 5:56
  • in same column, i have different formats. for example row 1 column 1 is text format but row2 column2 is number format, that is why i am trying to arrange my decimals by using localization. – bilen Commented Jul 1, 2017 at 2:54
  • 1 AFAIK only "sap.ui.model.type.Currency" supports localization. But since you have mixed Rows (String / Number) you might have to switch to "sap.ui.model.type.String", write a parser and attach it to the submit-Event – A.vH Commented Jul 3, 2017 at 15:16
 |  Show 1 more ment

1 Answer 1

Reset to default 3

This approach works for me : define the format based on the locale, e.g., in a formatter 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 you want to use it :

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

本文标签: javascriptSAPUI5Number Format LocalisationStack Overflow