The decround() function
The decround() function rounds a decimal type number to fractional digits.
Syntax
void decround(d, s)
dec_t *d;
mint s;
- d
- A pointer to the decimal structure that contains the value to round.
- s
- The number of fractional digits to round d. Use a positive
integer or zero (
0
) for this argument.
Usage
The rounding factor is 5x10-s-1.
To round a value, the decround() function adds
the rounding factor to a positive number or subtracts this factor
from a negative number. It then truncates to s digits, as the
following table shows.
Value before round | Value of s | Rounded value |
---|---|---|
1.4 | 0 | 1.0 |
1.5 | 0 | 2.0 |
1.684 | 2 | 1.68 |
1.685 | 2 | 1.69 |
1.685 | 1 | 1.7 |
1.685 | 0 | 2.0 |