Decimal¶
An xsd:decimal is a decimal number of arbitrary precision, but this implementation only supports values that fit in a double.
Unlike xsd:double, xsd:decimal is written in numeric form, never in scientific notation. Special infinity and NaN values are not supported. Note that the xsd:decimal representation for some numbers is very long, so xsd:double may be a better choice for values in a wide range.
Canonical form has no leading “+” sign, and at most 1 leading or trailing zero such that there is at least 1 digit on either side of the decimal point, like “12.34”, “-1.0”, and “0.0”.
Non-canonical form allows a leading “+”, any number of leading and trailing zeros, any number of digits (including zero) on either side of the point, and does not require a decimal point, like “+1”, “01”, “-.5”, “4.”, and “42”.
-
ExessResult
exess_read_decimal(double *out, const char *str)¶ Read an xsd:decimal string after any leading whitespace.
Values beyond the range of
decimalwill produce-INForINF, and return an error because these are not valid decimal values.- Parameters
out – Set to the parsed value, or NaN on error.
str – String input.
- Returns
The
countof characters read, and astatuscode.
-
ExessResult
exess_write_decimal(double value, size_t buf_size, char *buf)¶ Write a canonical xsd:decimal string.
- Parameters
value – Value to write.
buf_size – The size of
bufin bytes.buf – Output buffer, or null to only measure.
- Returns
The
countof characters in the output, andstatusExessStatus.EXESS_SUCCESS, orExessStatus.EXESS_NO_SPACEif the buffer is too small.
-
EXESS_MAX_DECIMAL_LENGTH¶ The maximum length of an xsd:decimal string from
exess_write_decimal(), 327.