3 releases

0.1.3 Mar 15, 2024
0.1.1 Mar 15, 2024
0.1.0 Mar 15, 2024

#11 in #round

MIT license

4KB

round2rs

Round a number to a specific number of decimal places: 1.2341.2 supports negative numbers as well

Install

cargo add round-to

Usage

use round_to::RoundTo;

RoundTo::round_to(1.234, 2);
//=> 1.23

RoundTo::round_to_ceil(1.234, 2);
//=> 1.24

RoundTo::round_to_floor(1.234, 2);
//=> 1.23

API

number

Type: number

The number to adjust.

precision

Type: number (Integer or infinity)

The number of decimal places.

No runtime deps