format.format(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Formats a value from the raw value to its appropriate preference format.

Note:

This method is overloaded when you format a datetime or datetimetz value.

Returns

If a datetime or datetimetz value is specified, the string in date format is returned in the user’s local app time zone.

Note:

If an invalid value is given, the original value passed to options.value is returned.

Note:

For client scripts, the string returned is based on the user’s system time. For server scripts, the string returned is based on the current time in the Pacific Time Zone. Daylight Savings Time does apply.

Supported Script Types

Client and server scripts

For more information, see SuiteScript 2.x Script Types

Governance

None

Module

N/format Module

Since

2015.2

Parameters

This method is overloaded when you format a datetime or datetimetz value.

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.value

Date | string | number

required

The input data to format.

2015.2

options.type

string

required

The field type (for example, DATE, CURRENCY, INTEGER).

Set using the format.Type enum.

2015.2

The table below applies to datetime and datetimetz values only.

Parameter

Type

Required / Optional

Description

Since

options.value

Date

required

The Date Object being converted into a string

2015.2

options.type

string

required

The field type (either DATETIME or DATETIMETZ).

Set using the format.Type enum.

2015.2

options.timezone

enum | number

optional

The time zone specified for the returned string. Set using the format.Timezone enum or key.

If a time zone is not specified, the time zone is set based on user preference.

If the time zone is invalid, the time zone is set to GMT.

2015.2

Syntax
Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/format Module Script Samples.

          // Add additional code
...
    function(format){
         function formatToString() {
              // Assume number format is 1.000.000,00 and negative format is (100)
              var rawNum2 =  -44444.44
              return format.format({value:rawNum2, type: format.Type.FLOAT}) 
              }
         var formattedNum2 = formatToString(); // "44.444,44" -- a string
...
// Add additional code 

        

Related Support Article

SuiteScript 2.0 > format.format(options) > Fails to convert string value to appropriate preference format

Related Topics

N/format Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices