简体   繁体   English

重击带点的小数点后两位

[英]Bash round 2 decimal places with dot

I used printf "%0.2f\\n" $myVar method to display something on 2 decimal places, but it doesnt work for numbers with dot (.) as decimal mark, but comma(,) 我使用printf“%0.2f \\ n” $ myVar方法在小数点后2位显示某些内容,但不适用于以点(。)作为小数点的数字,但逗号(,)

Anybody has any idea what should i do? 有人知道我该怎么办吗?

http://puu.sh/owM1p/21f5be08c2.jpg http://puu.sh/owM1p/21f5be08c2.jpg

Try setting your locale environment variable LC_NUMERIC to some locale that uses period. 尝试将您的语言环境环境变量LC_NUMERIC设置为某些使用句点的语言环境。 Eg 例如

LC_NUMERIC="C" printf "%0.2f\n" 3.1415

The locale needs to be installed in your system. 语言环境需要安装在您的系统中。 To get full list of the locales installed, use locale -a 要获取安装的语言环境的完整列表,请使用locale -a

PROBLEM WAS LOCALE as someone pointed out I didnt know what caused error and i thank you. 正如有人指出的那样,问题很普遍,我不知道是什么引起了错误,我谢谢你。

more on this link /bin/bash printf does not work with other LANG than C 关于此链接的更多信息/ bin / bash printf不适用于除C之外的其他LANG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM