简体   繁体   中英

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(,)

Anybody has any idea what should i do?

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

Try setting your locale environment variable LC_NUMERIC to some locale that uses period. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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