3 个不稳定版本
使用旧的 Rust 2015
0.1.2 | 2021年11月23日 |
---|---|
0.1.0 | 2016年7月28日 |
0.0.0 | 2016年7月28日 |
在 Rust 模式 中排名第 644
每月下载量 1,330
用于 7 个 软件包(6 个直接使用)
9KB
55 行
round
此软件包提供从 (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.