Number.format(decimalsN[,widthN])

Tinderbox Icon


Operator Type:   Function
Operator Scope of Action:   Item
Operator Purpose:   Formatting

Number.format(decimalsN[,widthN])

New to v5.8.0, returns Number as a string, formatted to decimalsN decimal places.

If widthN is supplied, Number returned additionally left padded with spaces so that places+Number(decimalsN) = widthN.

Note that with widthN, decimal character is not counted as part of the number

For example, if $MyNum is 3.1415927, then

$MyNum.format(2) is 3.14

$MyNum.format(0) is 3

$MyNum.format(2,7), is " 3.14" (3 spaces + number + period + 3 numbers = 7)

Literal numbers, e.g. 3.1415927, can also be worked with:

5.1415927.format(2) is 5.14

The above works but the following syntax may seem less ambiguous by using parentheses to delimit the literal number:

(5.1415927).format(2) is 5.14

(5.1415927).format(1,2) is '  5.1' (two left padding paces) 

Number.format("formatString")

New to v5.10.3, an alternate usage is to supply a quoted formatString. Currently only one such string is supported: "L". This will return a string of the number formatted with (OS) locale-dependent group & decimal delimiters. For example, for the US locale these are a comma and a period; in other locales they may vary.

This function supplements the existing format() and Number.precision() functions.


Possible relevant notes (via "Similar Notes" feature):

Up: Formatting operators

A Tinderbox Reference File : Actions & Rules : Operators : Action Operator Types : Formatting operators : Number.format(decimalsN[,widthN])

Quicklinks: Attributes | Action Codes | Export Codes | Designators | Date Formats | aTbRef Site Map

[Last updated: 16 May 2012, using v5.11.1]


Search:

Google search aTbRef for:  


Creative Commons Licence

aTbRef by Mark Anderson is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

[See aTbRef CC licence Attribution & Waiver info]

Made with Tinderbox