O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

format — Convert a value into a string with control over the formatting

Usage

String.format(format, value)

format : String

value : Anything

Description

Returns a string containing value converted to a string under the control of the format string. The behavior of format is similar to the format string for the C language printf( ) function, but it’s simplified.

The format string can contain any characters and one format specifier, which is replaced with the converted value in the result. There are three variants of the format specifier, and in all cases any part inside [] may be omitted:

% [width][.max] s

Formats a string value: value is converted to a string with the normal WMLScript conversion rules. If max is specified, no more than that many characters from the string are included in the result. If width is specified, and the formatted part of the string has fewer than that many characters, it’s padded on the left with spaces.

% [width][.digits] d

Formats a decimal integer value: value is converted to an integer with the normal WMLScript conversion rules. If digits is specified and the number has fewer than that many digits, it’s padded with zeros. If max is specified as zero, and value is zero, the result is an empty string. After this, if width is specified, and the value still has fewer than that many characters, it’s padded on the left with spaces.

% [width][.digits] f

Formats a floating-point value: value is converted to floating-point with the normal WMLScript conversion ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required