Format Currency Based on the Locale Parameter
The following sample formats currency 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 curFormatter = format.getCurrencyFormatter({
locale: "IT_IT"
});
var curCur = curFormatter.currency; // curCur is 'EUR'
var sym = curFormatter.symbol; // sym is '€'
var numberFormat = curFormatter.numberFormatter;
var gs = numberFormat.groupSeparator; // gs is '.'
var ds = numberFormat.decimalSeparator; // ds is ','
var prec = numberFormat.precision; // prec is 2
var nnf = numberFormat.negativeNumberFormat; // nnf is MINUS
var currency1 = curFormatter.format({
number: 123456.55
});// currency1 is '€123.456,55'
var currency2 = curFormatter.format({
number: -123456.55
}); // currency2 is '€-123.456,55'
});