Format Numbers as Currency Strings
The following sample formats numbers as currency strings.
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({
currency: "EUR"
});
var curCur = curFormatter.currency; // curCur is 'EUR'
var numberFormat = curFormatter.numberFormatter;
var curSymbol = curFormatter.symbol; // curSymbol is '€'
var curSeparator = numberFormat.groupSeparator; // curSeparator is ' '
var curDecimalSep = numberFormat.decimalSeparator; // curDecimalSep is ','
var curPrecision = numberFormat.precision; // curPrecision is 2
var curNNF = numberFormat.negativeNumberFormat; // curNNF is MINUS
curFormatNum1 = curFormatter.format({
number: 12.53
}); // curFormat1 is '€12,53'
curFormatNum2 = curFormatter.format({
number: -5421
}); // curFormat2 is '€-5 421,00'
curFormatNum3 = curFormatter.format({
number: 0.00
}); // curFormat3 is '€0,00'
curFormatNum4 = curFormatter.format({
number: 0.3456789
}); // curFormat4 is '€0,35'
});
Related Topics
- N/format/i18n Module Script Samples
- Format 12345 as a German String
- Format a Number as a String Using N/format/i18n
- Parse a Czech Phone Number
- Parse a U.S. Phone Number
- Format Numbers Based on the Locale Parameter
- 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