Format a Number as a String Using N/format/i18n
The following sample formats a number as a string.
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.1 Script Basics and SuiteScript 2.1 Script Types.
/**
* @NApiVersion 2.1
*/
require(['N/format/i18n'], (format) => {
const formatNumbers = () => {
// Use the default formatter's separators, precision, and negative format.
const numberFormatter = format.getNumberFormatter();
const gs = numberFormatter.groupSeparator;
const ds = numberFormatter.decimalSeparator;
const precision = numberFormatter.precision;
const nnf = numberFormatter.negativeNumberFormat;
const formatNum1 = numberFormatter.format({
number: 12.53
});
const formatNum2 = numberFormatter.format({
number: 12845.22
});
const formatNum3 = numberFormatter.format({
number: -5421
});
const formatNum4 = numberFormatter.format({
number: 0.00
});
const formatNum5 = numberFormatter.format({
number: 0.3456789
});
return { gs, ds, precision, nnf, formatNum1, formatNum2, formatNum3, formatNum4, formatNum5 };
};
return { formatNumbers };
});
Related Topics
- N/format/i18n Module Script Samples
- Format 12345 as a German String
- Format Numbers as Currency Strings
- 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.1 Modules
- SuiteScript 2.1