linuxbashprintfdecimalrounding

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


Solution

  • Try setting your locale environment variable LC_NUMERIC to some locale that uses period. E.g.

    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