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.
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 SuiteScript
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category