CAPL Script

gcvt

This reference collection includes Vector documentation reproduced with permission. Snippets may require configuration-specific symbols and are not all standalone programs. Sources and validation limits.

Syntax

void _gcvt(double val, int digits, char s[]);

Function

The numbervalis converted to a stringscontaining a decimal point and a possible sign byte.

Parameters

val Number to be converted.

digits

Number of significant digits.

s

String, which contains the converted number. If the string size is too small, the string stays unchanged.

Return Values

—

char s[15];
float val1 = 3.1415926535;
float val2 = 271828.18284;
_gcvt(val1, 10, s);
writeToLogEx("val1: %f: s: %s", val1, s);
_gcvt(val2, 9, s);
writeToLogEx("val2: %f: s: %s", val2, s);
_gcvt(val2, 5, s);
writeToLogEx("val2: %f: s: %s", val2, s);
// The destination is too small for 20 significant digits.
_gcvt(val2, 20, s);
writeToLogEx("val2: %f: s: %s", val2, s);

Related reference: atol | ltoa