Help

JS-STRING-F

Also: JS-STRING-PRINTF

The JavaScript String f() ("f" is for "format") method adds C-style printf() formatting functionality to the String object. The f() method works similarly to the C-printf() functionality so if you are familiar with that, using this function should be straightforward.

The f() method supports the following format specifiers:

Strings: %[-][field digits][.string digits]s

Normally strings are right-justified, but specifying the - option will left-justify them. field digits specifies how wide the displayed field should be. string digits specifies the maximum number of characters to use from the string.

Decimals: %[+][-][0][field digits][.radix digits]f

Normally a sign is displayed before numbers only if the number is negative but if the + option is given, a plus sign will be shown in front of positive numbers as well. Normally numbers are left-justified, but specifying the - option will right-justify them. Specifying the 0 option will pad numbers with zeroes instead of spaces. field digits specifies how many characters wide the entire number field should take up. If this number is larger than the number of digits in the number, the number will be padded. radix digits specifies how many digits to show to the right of the decimal point.

Integers: %[+][-][0][field digits][.integer digits]d

Normally a sign is displayed before numbers only if the number is negative but if the + option is given, a plus sign will be shown in front of positive numbers as well. Normally numbers are left-justified, but specifying the - option will right-justify them. Specifying the 0 option will pad numbers with zeroes instead of spaces. field digits specifies how wide the displayed field should be. integer digits specifies how many digits long the number should be. The number will be padded with zeroes if it is shorter than integer digits.

See JS-STRING-F-EXAMPLES for examples.