How to separated zero with point in my bash script? [closed]

扶醉桌前 提交于 2019-12-14 03:37:42

问题


My script

 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";

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

I want :

Your result : 100000 + 100000 = 200.000

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


回答1:


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


来源:https://stackoverflow.com/questions/16621154/how-to-separated-zero-with-point-in-my-bash-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!