rounding

There are four rounding modes:

`trunc`

– zeroes the fractional part of the number`floor`

– rounds the number down`ceil`

– round the number up`round`

– rounds the number to the closest integer

Rounding table:

x | round(x) | floor(x) | ceil(x) | trunc(x) |
---|---|---|---|---|

2.3 | 2 | 2 | 3 | 2 |

3.8 | 4 | 3 | 4 | 3 |

5.5 | 6 | 5 | 6 | 5 |

-2.3 | -2 | -3 | -2 | -2 |

-3.8 | -4 | -4 | -3 | -3 |

-5.5 | -5 | -6 | -5 | -5 |

Every rounding mode is available as two functions. The ones with the `i`

prefix in the name return an integer, while the ones without return a fixed-point number:

rounding.txt · Last modified: 2017/06/12 18:59 by korshun