#精度 #四舍五入 #十进制 #浮点数

round

此软件包提供从1到10的精度对浮点数进行四舍五入的实用工具

3 个不稳定版本

使用旧的 Rust 2015

0.1.2 2021年11月23日
0.1.0 2016年7月28日
0.0.0 2016年7月28日

Rust 模式 中排名第 644

Download history 274/week @ 2024-03-13 257/week @ 2024-03-20 273/week @ 2024-03-27 322/week @ 2024-04-03 276/week @ 2024-04-10 332/week @ 2024-04-17 337/week @ 2024-04-24 212/week @ 2024-05-01 204/week @ 2024-05-08 219/week @ 2024-05-15 224/week @ 2024-05-22 293/week @ 2024-05-29 277/week @ 2024-06-05 383/week @ 2024-06-12 425/week @ 2024-06-19 206/week @ 2024-06-26

每月下载量 1,330
用于 7 软件包(6 个直接使用)

GPL-2.0 许可证

9KB
55

round crates.io

此软件包提供从 (round, round_up, round_down) 对浮点数进行1到10精度四舍五入的实用工具。

用法

在您的项目 Cargo.toml 中包含软件包名称和版本,如下所示

[dependencies]
round = "0.1.0" // or any latest version on crates.io

示例

extern crate round;
use round::{round, round_up, round_down};

fn main() {
    // basic rounding
    let test_n = round(8.9534, 2);  // 8.95
    let test_x = round(8.9536, 3);  // 8.954
    let test_y = round(8.9536, -1); // 8.95

    // rounding up
    let test_j = round_up(8.9534, 2); // 8.96
    let test_k = round_up(8.9536, 3); // 8.954

    // rounding down
    let test_l = round_down(8.9534, 2); // 8.95
    let test_m = round_down(8.9536, 3); // 8.953
}

默认为2位小数四舍五入(round, round_up, round_down),如果所选小数位数(i32)为负数或大于10。

API

round, round_up, round_down 从0到10的精度

动机

结果证明,我几乎每天都需要这种类型的操作。希望它也能为您节省一些时间。

许可证

此库以 GPLv2 软件许可证分发。

    round (rust library - crate)
    Copyright (C) 2016 - Mohamed Hayibor

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

无运行时依赖项