Specifies how many digits before and after the decimal point a computed number should have.


set the numberFormat [of <scrollbar>] to <formatExpression>


set the numberFormat to "#.00" -- dollar format
set the numberFormat of scrollbar "Progress" to "0.0"

If there are zeros after the decimal point, the number of zeros indicates the number of digits after the decimal point in a calculated number. If there are more digits after the decimal point, the number is truncated. If there are fewer digits, trailing zeros are added.

If there are hash marks after the decimal point, the number of hash marks indicates the maximum number of digits after the decimal point. If there are more digits, the number is truncated, but if there are fewer digits, no trailing zeroes are added.

Changing the numberFormat does not automatically change the format of a number that's already in a container. It affects numbers only when they are calculated and then displayed or used as strings. Otherwise, the number retains its full numeric precision.

Since the numberFormat is a local property, its value is reset to 0.###### when the current handler finishes executing. It retains its value only for the current handler, and setting it in one handler does not affect its value in other handlers it calls. (The numberFormat of a scrollbar is not reset in this way.)

Since LiveCode does not use decimal numbers for its internal calculations (for reasons of speed), the decimal representation of a number is sometimes slightly off the correct number. For example, 10^-1 is equal to 0.1, but is calculated (to eighteen decimal places) as 0.100000000000000006. Because of this, setting the numberFormat to specify many decimal places after the decimal point may produce unexpected results in a statement that tests for an exact number. To prevent this, either avoid setting the numberFormat to a value more precise than you need, or use the abs function instead of the = operator to test equality:

   set the numberformat to ".##################"
   put 10^-1 = 0.1 -- reports false because of the decimal error
   put abs((10^-1) - 0.1) = zero -- reports true

See also: format (function), value (function), abs (function), scrollbar (object), showValue (property),