The default roundmode to statement sets the default rounding behavior for calculations performed in the current script.
default roundmode to mode
• mode – An integer corresponding to one of the following constants:
Constant |
Description |
Examples* |
---|---|---|
ROUNDMODE_UP |
Always round up. |
4.651 –> 4.66 4.655 –> 4.66 4.659 –> 4.66 |
ROUNDMODE_DOWN |
Always round down. |
4.651 –> 4.65 4.655 –> 4.65 4.659 –> 4.65 |
ROUNDMODE_HALF_UP |
If the only digit following the digit to be rounded is 5, round up. |
4.675 –> 4.68 4.6751 –> 4.68 |
ROUNDMODE_HALF_DOWN |
If the only digit following the digit to be rounded is 5, round down. |
4.675 –> 4.67 4.6751 –> 4.68 |
ROUNDMODE_HALF_EVEN |
If the only digit following the digit to be rounded is 5 and the preceding digit is odd, round up. Otherwise, truncate. |
4.675 –> 4.68 4.685 –> 4.68 |
ROUNDMODE_CEILING |
Always round toward positive infinity. |
4.655 –> 4.66 -4.655 –> -4.65 |
ROUNDMODE_FLOOR |
Always round toward negative infinity. |
4.655 –> 4.65 -4.655 –> -4.66 |
*Rounding to two decimal places |
Functions such as round() and truncate() have their own rounding mode. They don’t use the mode specified by the default roundmode to statement.