Changing String Output Length of Floating Point Numbers

Casting a float to string outputs a string with six significant decimal digits by default. Casting a double value to a string outputs with 15 significant decimal digits by default.

Casting a Floating Point Number to a String

You can reduce the number of significant decimal digits by specifying an integer value less than or equal to the default as shown below.


Cast float to string

Default cast of float to string


$ iquery -w 15 -aq "build(<str:string>[i=1:1], string(float(i/67.0)))"

{i} str
{1} '0.0149254'

Cast of float to string with three significant decimal digits (less than 6)

$ iquery -w 15 -aq "build(<str:string>[i=1:1], string(float(i/67.0), 3))"
{i} str
{1} '0.0149'

Attempt to cast of double to string with 100 signficiant decimal digits (greater than 6).

iquery -w 100 -aq "build(<str:string>[i=1:1], string(float(i/67.0), 100))"
{i} str
{1} '0.0149254'

Cast double to string

Default cast of double to string

$ iquery -w 15 -aq "build(<str:string>[i=1:1], string(i/67.0))"
{i} str
{1} '0.0149253731343284'

Cast of double to string with ten significant decimal digits (less than 15)

$iquery -w 15 -aq "build(<str:string>[i=1:1], string(i/67.0, 10))"
{i} str
{1} '0.01492537313'

Attempt to cast of double to string with 100 signficiant decimal digits (greater than 15).

$iquery -w 100 -aq "build(<str:string>[i=1:1], string(i/67.0, 100))"
{i} str
{1} '0.0149253731343284'

The number of significant decimal digits in the output is limited to a maximum of six for float data types and 15 for double data types.Â