Wijmo UI for the Web
format Method
wijmo.input Namespace > IFormatValidateLib Interface : format Method
The value to format. The value can be one of three types: date, string, or number.
The formatting to apply to the value. Depending on the value type, this parameter can take a dateFormat or maskFormat value, or a number type can be specified as currency, numeric, or percent.
Other formatting options to apply to the value. Depending on the value type, this parameter can take an IDateOptionsIMaskOptions, or INumberOptions object.

Use this method to format the specified value and return it as a string using the specified format (or type) and options. To use this method, instead of wijmo.input.IFormatValidateLib.format, use $.wijinputcore.format. See examples below for the correct usage.

Internally, wijinput widgets use the same format library. The formatting logic used depends on the value type. Valid types are: 

Date

For date values, the format library uses wijinputdate logic.
The formatOrType parameter is a string value. It can take a valid wijinputdate dateFormat value.
The options parameter can take an IDateOptions object or it can be null.

String

For string values, the format library uses wijinputmask logic.
The formatOrType parameter is a string value. It can take a valid wijinputmask maskFormat value, but RegEx maskFormat values are invalid.
The options parameter can take an IMaskOptions object or it can be null.

Number

For number values, the format library uses wijinputnumber logic.
The formatOrType parameter is a string value. It can take one of three values:

The options parameter can take an INumberOptions object or it can be null.

Syntax
var instance; // Type: wijmo.input.IFormatValidateLib;
var returnValue; // Type: string

// Parameters
var value; // Type:  any
var formatOrType; // Type:  string
var options; // Type:  any

returnValue = instance.format(value, formatOrType, options);
function format( 
   value : any,
   formatOrType : string,
   options : any
) : string;

Parameters

value
The value to format. The value can be one of three types: date, string, or number.
formatOrType
The formatting to apply to the value. Depending on the value type, this parameter can take a dateFormat or maskFormat value, or a number type can be specified as currency, numeric, or percent.
options
Other formatting options to apply to the value. Depending on the value type, this parameter can take an IDateOptionsIMaskOptions, or INumberOptions object.

Return Value

A string value formatted according to the specified parameters.
Example
$.wijinputcore.format(new Date(2013,8,12));   // returns: "9/12/2013"
    $.wijinputcore.format(new Date(2013,8,12), "yyyy/MM/dd");  // returns: "2013/09/12"
    $.wijinputcore.format(new Date(2013,8,12),{culture: "ja-JP"});   // returns: "2013/09/12"
    $.wijinputcore.format(new Date(2013,8,12,23,22,33), "tt hh:mm:ss", {culture: "ja-JP"});   // returns: "午後 11:22:33"
    $.wijinputcore.format(new Date(2013,8,12,24,12,12), "HH:mm:ss", {midnightAs0: true});   // returns: "00:12:12"
   
    $.wijinputcore.format("1234567", "999-9999", {autoConvert: true});   // returns: "123-4567"
    $.wijinputcore.format("1234567", "999-9999", {autoConvert: false});  //  returns: "       "
    
    $.wijinputcore.format(12345);   // returns: "12345.00"
    $.wijinputcore.format(12345, "numeric", {decimalPlaces:3});   // returns: "12345.000"
    $.wijinputcore.format(12345, "percent");   // returns: "12345.00 %"
    $.wijinputcore.format(12345, "currency");  // returns: "$12345.00"
    $.wijinputcore.format(12345, "currency", {culture: "ja-JP"});   // returns: "¥12345.00"
    $.wijinputcore.format(12345, "numeric", {positivePrefix: "+", negativePrefix: "-"});   // returns: "+12345.00"
See Also

Reference

IFormatValidateLib Interface
dateFormat Option
maskFormat Option
IDateOptions Interface
IMaskOptions Interface
INumberOptions Interface

Concepts

Format Function Library