Number Formatter Object Members in SuiteScript

The Number Formatter object in SuiteScript formats numbers to strings, supporting custom separators and precision settings.

·2 min read·1 views·View Oracle Docs

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 NameTypeSupported Script TypesDescription
NumberFormatter.groupSeparatorstringClient and server scriptsSpecifies the group separator (e.g., thousand separator).
NumberFormatter.decimalSeparatorstringClient and server scriptsSpecifies the decimal separator (e.g., period or comma).
NumberFormatter.localestringClient and server scriptsDesignates the locale setting for the formatter.
NumberFormatter.precisionnumberClient and server scriptsIndicates the decimal precision for formatted numbers.
format.NegativeNumberFormatenumClient and server scriptsSpecifies how negative numbers are formatted.
NumberFormatter.format(options)stringClient and server scriptsFormats a given number per the defined settings.

Implementation Example

Here’s a sample implementation demonstrating how to utilize the Number Formatter object:

suitescript
1// Add additional code
2...
3var numFormatter1 = format.getNumberFormatter(); // Default number formatter object returned
4
5var numFormatter2 = format.getNumberFormatter({
6 groupSeparator: " ",
7 decimalSeparator: ",",
8 precision: 2,
9 negativeNumberFormat: format.NegativeNumberFormat.MINUS
10});
11
12var number1 = numFormatter1.format({
13 number: 12.53
14}); // number1 is '12.53'
15
16var number2 = numFormatter2.format({
17 number: 12845.22
18}); // number2 is '12 845,22'
19...
20// Add additional code

Conclusion

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?
You can specify a custom group separator by setting the 'groupSeparator' property on the Number Formatter object in both client and server scripts.
Is it possible to define locale settings with the Number Formatter object in SuiteScript?
Yes, the 'locale' property of the Number Formatter object allows you to designate specific locale settings for formatting numbers.
Do I need to use a specific module to access the Number Formatter object in SuiteScript?
Yes, the Number Formatter object is part of the SuiteScript 2.x framework and is accessed via the 'N/format/i18n' module.
Can the Number Formatter object handle negative numbers differently based on preferences?
Yes, you can specify how negative numbers are formatted by using the 'format.NegativeNumberFormat' enum, which is supported in both client and server scripts.
Source: Number Formatter Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Platform

View all Platform articles →