如何在我的bash脚本分离与零点? [英] How to separated zero with point in my bash script?

查看:105
本文介绍了如何在我的bash脚本分离与零点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的剧本

 echo -n "number 1 : ";
 read bil1
 echo -n "number 2 :";
 read bil2
 jlh=$(echo $bil1 + $bil2 |bc -l |sed -e 's/^\./0./' -e 's/^-\./-0' -e 's/\.0*$//');
 echo " Your result : $bil1 + $bil2 = $jlh";

如果我在$ bil1输入100000和100000,在$ bil2,结果是200000。

if I input " 100000 " in $bil1 and "100000 " in $bil2 , the result is " 200000 ".

我想:

Your result : 100000 + 100000 = 200.000

如何使用分隔零。对于结果从20万200.000?

how to separated zero with " . " for that result from 200000 to 200.000 ?

推荐答案

如果您的libc支持它,在的printf 标志code>说明会石斑鱼增加了许多。

If your libc supports it, the ' flag in a printf specifier will add groupers to a number.

$ LC_NUMERIC=en_US printf "%'d\n" 100000
100,000
$ LC_NUMERIC=fr_FR printf "%'d\n" 100000
100 000
$ LC_NUMERIC=de_DE printf "%'d\n" 100000
100.000
$ LC_NUMERIC=bn_IN printf "%'d\n" 100000
1,00,000

这篇关于如何在我的bash脚本分离与零点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆