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.

·3 min read·View Oracle Docs

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:

NameTypeSupported Script TypesDescription
format.CurrencyFormatterObjectClient and server scriptsFormats numbers to currency strings.
format.NumberFormatterObjectClient and server scriptsFormats numbers to strings.
format.PhoneNumberFormatterObjectClient and server scriptsFormats phone numbers to strings.
format.PhoneNumberParserObjectClient and server scriptsParses strings into phone numbers.

Methods

Methods are key to utilizing the objects effectively:

NameReturn TypeSupported Script TypesDescription
format.spellOut(options)stringClient and server scriptsProduces a string representation of numbers in a specified locale.
format.getCurrencyFormatter(options)objectClient and server scriptsInstantiates a format.CurrencyFormatter object.
format.getNumberFormatter(options)objectClient and server scriptsInstantiates a format.NumberFormatter object.
format.getPhoneNumberFormatter(options)objectClient and server scriptsInstantiates a format.PhoneNumberFormatter object.
format.getPhoneNumberParser(options)objectClient and server scriptsInstantiates a format.PhoneNumberParser object.

Enumerations

The module also includes enumerations useful for setting options:

NameTypeSupported Script TypesDescription
format.NegativeNumberFormatenumClient and server scriptsDefines negative number format options.
format.CurrencyenumClient and server scriptsRepresents currency code values.

Practical Example

Here's a basic example demonstrating how to format a currency string using the N/format/i18n module:

javascript
1// Sample SuiteScript using N/format/i18n module
2require(['N/format'], function(format) {
3 var curFormatter = format.getCurrencyFormatter({
4 currency: format.Currency.USD
5 });
6 var formattedCurrency = curFormatter.format(12345.67);
7 console.log(formattedCurrency); // Outputs the formatted currency string
8});

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?
Yes, the N/format/i18n module can be used in both client and server scripts, providing flexibility for various SuiteScript applications.
How does the module handle negative numbers when formatting?
The module includes the 'format.NegativeNumberFormat' enumeration, which defines options for formatting negative numbers in both client and server scripts.
What objects does the N/format/i18n module offer for phone number manipulation?
The module provides the 'format.PhoneNumberFormatter' and 'format.PhoneNumberParser' objects for formatting and parsing phone numbers, respectively.
How do you instantiate a CurrencyFormatter using the N/format/i18n module?
You can instantiate a CurrencyFormatter by using the 'format.getCurrencyFormatter(options)' method, specifying the desired currency through options such as 'format.Currency.USD'.
Source: N/format/i18n Module 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 →