The NumberFormat class can be used to parse a string representing a number (float or integer) into a JavaScript number and vice versa (also known as format).
The following format options are possible. For unspecified parameters, default values according to the type are used:
The following code snippet shows an example how the NumberFormat class can be used:
#!js var fValue = 20001000.563; jQuery.sap.require("sap.ui.core.format.NumberFormat"); var oNumberFormat = sap.ui.core.format.NumberFormat.getFloatInstance({ maxFractionDigits: 2, groupingEnabled: true, groupingSeparator: ",", decimalSeparator: "." }); //Returns a NumberFormat instance for float /*var oNumberFormat = sap.ui.core.format.NumberFormat.getIntegerInstance({ maxFractionDigits: 0, groupingEnabled: false }); //Returns a NumberFormat instance for integer*/ var oField = new sap.ui.commons.TextField(); oField.setValue(oNumberFormat.format(fValue)); // Set the formatted value on the text field oField.attachChange(function(){ //Parse the user input fValue = oNumberFormat.parse(oField.getValue()); alert(fValue); });