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.
Source: This article is based on Oracle's official NetSuite documentation.
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 Platform
- Style Object Members for Workbook API in NetSuite
The Style object provides customizable properties for workbook formatting in NetSuite, enhancing report and visualization functionality.
- Asynchronous HTTP Requests with SuiteScript Promises
Use SuiteScript to send asynchronous HTTP requests with promises for efficient error handling and response processing.
- Setting Sublist Field Values in SuiteScript
Set values for sublist fields in SuiteScript using the setSublistValue method. Understand required parameters and error handling.
- In This Help Topic
Explore N/log module guidelines, log levels, and script execution logs for efficient logging in SuiteScript.
Advertising
Reach Platform Professionals
Put your product in front of NetSuite experts who work with Platform every day.
Sponsor This Category