WMLScript format() Function
The format() function formats a value.
Syntax
n = String.format(format, value)
Component | Description |
---|---|
n | The string returned from the function. |
format | Specifies how to format the value. |
value | The value to be formatted. |
The format consists of three parts: %width.precision type
width - Optional. Specifies the minimum number of output characters.
precision - Optional. Sets the precision of the output value. The following values can be used:
- d - Minimum number of output digits. Defaults to 1.
- f - Number of decimal places. Defaults to 6.
- s - Maximum number of output characters. Defaults to output all characters.
type - Required. Determines how the formatted value is interpreted. The following values can be used:
- d - Integer
- f - Floating Point
- s - String
Example
var b = String.format("%4.3d", 32); var d = String.format("%3f", 10.1234); var e = String.format("%2.2f", 2.3)
Result
b = " 032" d = "10.123" e = "2.30"