suve

awful: function: float-precision

Declaration

int :float-precision ( int $PRECISION )
int :float-precision

Summary

When passed a parameter, sets the float-to-string precision to PRECISION digits after the fraction separator. When passed no arguments, does not affect the precision setting. Returns the current float-to-string precision value.

Note that this affects not only float-to-string typecasts, but also printing floats by :write and :str-write calls.

Particularly small/large numbers will always be represented using scientific (exponent) format. Also, due to limited range a floating-point value can represent, setting the precision higher than 16-20 digits (platform-dependent) will most likely yield no effect.

Default float-to-string precision, set upon interpreter start, is 3 digits.

Example

# Default precision, upon interpreter start, is 3.
!const =Pi f3.14159265358979323
:writeln =Pi   # Will print 3.142
:float-precision i5
:writeln =Pi   # Will print 3.14159
:float-precision i10
:writeln =Pi   # Will print 3.1415926536

wikistrona zmodyfikowana 2014/0601/2317