小编bla*_*edx的帖子

如何在bash中使用bc四舍五入?

我想要使​​用 bash 脚本的快速示例:

#!/bin/bash
echo "Insert the price you want to calculate:"
read float
echo "This is the price without taxes:"
echo "scale=2; $float/1.18" |bc -l
read -p "Press any key to continue..."
bash scriptname.sh
Run Code Online (Sandbox Code Playgroud)

假设价格是:48.86 答案将是:41.406779661(实际上是 41.40 因为我正在使用scale=2;

我的问题是: 我如何舍入第二个小数以这种方式显示答案?:41.41

bash scripts bc

51
推荐指数
5
解决办法
14万
查看次数

标签 统计

bash ×1

bc ×1

scripts ×1