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'
}); 

        

General Notices