N/format/i18n Module Features for SuiteScript Development
Utilize the N/format/i18n module to format strings, currency, and phone numbers in NetSuite SuiteScript effectively.
The N/format/i18n module is a powerful tool in NetSuite SuiteScript that enables developers to format strings for international contexts, convert numbers into currency formats, and parse phone numbers from strings. This functionality is essential for creating applications that cater to a global audience and ensure that financial data is presented correctly and intuitively for diverse users.
What Does the N/format/i18n Module Offer?
The N/format/i18n module provides multiple tools for handling internationalization in your SuiteScript applications. Here are some key functionalities:
- Currency Formatting: Format numerical values as currency strings tailored to various locales.
- Number Formatting: Convert raw numerical values into user-friendly string representations.
- Phone Number Formatting and Parsing: Format and parse phone numbers to/from strings, ensuring accuracy in data handling.
Key Members of the N/format/i18n Module
The N/format/i18n module consists of several member types including objects, methods, and enumerations, which are utilized for various formatting tasks.
Objects
The following objects can be instantiated from the module:
| Name | Type | Supported Script Types | Description |
|---|---|---|---|
format.CurrencyFormatter | Object | Client and server scripts | Formats numbers to currency strings. |
format.NumberFormatter | Object | Client and server scripts | Formats numbers to strings. |
format.PhoneNumberFormatter | Object | Client and server scripts | Formats phone numbers to strings. |
format.PhoneNumberParser | Object | Client and server scripts | Parses strings into phone numbers. |
Methods
Methods are key to utilizing the objects effectively:
| Name | Return Type | Supported Script Types | Description |
|---|---|---|---|
format.spellOut(options) | string | Client and server scripts | Produces a string representation of numbers in a specified locale. |
format.getCurrencyFormatter(options) | object | Client and server scripts | Instantiates a format.CurrencyFormatter object. |
format.getNumberFormatter(options) | object | Client and server scripts | Instantiates a format.NumberFormatter object. |
format.getPhoneNumberFormatter(options) | object | Client and server scripts | Instantiates a format.PhoneNumberFormatter object. |
format.getPhoneNumberParser(options) | object | Client and server scripts | Instantiates a format.PhoneNumberParser object. |
Enumerations
The module also includes enumerations useful for setting options:
| Name | Type | Supported Script Types | Description |
|---|---|---|---|
format.NegativeNumberFormat | enum | Client and server scripts | Defines negative number format options. |
format.Currency | enum | Client and server scripts | Represents currency code values. |
Practical Example
Here's a basic example demonstrating how to format a currency string using the N/format/i18n module:
1// Sample SuiteScript using N/format/i18n module2require(['N/format'], function(format) {3 var curFormatter = format.getCurrencyFormatter({4 currency: format.Currency.USD5 });6 var formattedCurrency = curFormatter.format(12345.67);7 console.log(formattedCurrency); // Outputs the formatted currency string8});Who This Affects
This documentation is relevant to:
- Developers: Who are implementing script solutions in NetSuite.
- Administrators: Ensuring that applications are configured to adapt to various locales and currencies appropriately.
Key Takeaways
- The N/format/i18n module assists in formatting currencies, numbers, and phone numbers for international use.
- Multiple object types and methods enable flexible string formatting in scripts.
- The module is vital for developers aiming to create globally recognized applications.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
Can the N/format/i18n module be used in both client and server scripts?
How does the module handle negative numbers when formatting?
What objects does the N/format/i18n module offer for phone number manipulation?
How do you instantiate a CurrencyFormatter using the N/format/i18n module?
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