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 ...

Get Learning WML, and WMLScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.