Let's say I have a variable and I want to print 5 significant digits after I multiplied it by 1000. zsh
can do it:
zsh$ x=2.8026407e+00
zsh$ printf "%.5g\n" "$(( 1000*${x} ))"
zsh> 2802.6
Can bash
do it as well?
bash$ x=2.8026407e+00
bash$ printf "%.5g\n" "$(( 1000*${x} ))"
bash> bash: 1000*2.8026407e+00 : syntax error: invalid arithmetic operator (error token is ".8026407e+00 ")
I think there is no way to make native bash understand floating point operations, is there? I know I can use e.g. awk
, but I was wondering if bash
could do this at all or not.
(I'm not surprised that bash
cannot handle floats, but that zsh
can!)