Format Numbers Based on the Locale Parameter
The following sample formats numbers based on the locale parameter.
Note:
This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.
/**
* @NApiVersion 2.x
*/
require(['N/format/i18n'], function(format) {
var numberFormatter = format.getNumberFormatter({
locale: "fr_FR"
});
var gs = numberFormatter.groupSeparator; // gs is ' '
var ds = numberFormatter.decimalSeparator; // ds is ','
var prec = numberFormatter.precision; // prec is 2
var nnf = numberFormatter.negativeNumberFormat; // nnf is MINUS
var number1 = numberFormatter.format({
number: 123456.55
}); // number1 is '123 456,55'
var number2 = numberFormatter.format({
number: -123456.55
}); // number2 is '-123 456,55'
});
Related Topics
- N/format/i18n Module Script Samples
- Format 12345 as a German String
- Format a Number as a String Using N/format/i18n
- Format Numbers as Currency Strings
- Parse a Czech Phone Number
- Parse a U.S. Phone Number
- Format Currency Based on the Locale Parameter
- Format Numbers and Currencies Based on the English-India Locale Parameter
- SuiteScript 2.x Modules
- SuiteScript 2.x