Number Formatter Object Members in SuiteScript
The Number Formatter object in SuiteScript formats numbers to strings, supporting custom separators and precision settings.
The Number Formatter object provides various members that enable users to format numbers into strings accurately, using specific locale settings and rules. This article outlines its primary properties, methods, and their implementation in both client and server scripts.
What is the Number Formatter Object?
The Number Formatter object is part of the SuiteScript 2.x framework, specifically within the N/format/i18n module, and is utilized to convert numerical values into formatted string representations.
Key Object Members
The following members are available on the format.NumberFormatter object:
| Member Name | Type | Supported Script Types | Description |
|---|---|---|---|
NumberFormatter.groupSeparator | string | Client and server scripts | Specifies the group separator (e.g., thousand separator). |
NumberFormatter.decimalSeparator | string | Client and server scripts | Specifies the decimal separator (e.g., period or comma). |
NumberFormatter.locale | string | Client and server scripts | Designates the locale setting for the formatter. |
NumberFormatter.precision | number | Client and server scripts | Indicates the decimal precision for formatted numbers. |
format.NegativeNumberFormat | enum | Client and server scripts | Specifies how negative numbers are formatted. |
NumberFormatter.format(options) | string | Client and server scripts | Formats a given number per the defined settings. |
Implementation Example
Here’s a sample implementation demonstrating how to utilize the Number Formatter object:
1// Add additional code2...3var numFormatter1 = format.getNumberFormatter(); // Default number formatter object returned4 5var numFormatter2 = format.getNumberFormatter({6 groupSeparator: " ",7 decimalSeparator: ",",8 precision: 2,9 negativeNumberFormat: format.NegativeNumberFormat.MINUS10});11 12var number1 = numFormatter1.format({13 number: 12.5314}); // number1 is '12.53'15 16var number2 = numFormatter2.format({17 number: 12845.2218}); // number2 is '12 845,22'19...20// Add additional codeConclusion
Understanding how to implement the Number Formatter object allows developers to ensure consistency and clarity in numerical data displayed within the NetSuite interface. Its flexibility with locales and formatting enhances user interactions with numeric data.
Key Takeaways
- The Number Formatter object simplifies number formatting in SuiteScript.
- Custom group and decimal separators can be specified.
- Supports both client and server scripts for versatility in usage.
Frequently Asked Questions (4)
How can I specify a custom group separator using the Number Formatter in SuiteScript?
Is it possible to define locale settings with the Number Formatter object in SuiteScript?
Do I need to use a specific module to access the Number Formatter object in SuiteScript?
Can the Number Formatter object handle negative numbers differently based on preferences?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
