Bash doesn't support floating point .
Ksh supports floating point perfectly[bash]$printf "%.2f\n", $((10.0/3.0))-bash: 10.0/3.0: syntax error in expression (error token is ".0/3.0")
[ksh]$ printf "%.2f\n", $((10.0/3.0))
Because the input (10.0, 3.0) are floating point, the output will be floating point by default, but you can force to treat it as integer.3.33
[ksh]$ integer x
External commands supporting floating point[ksh]$ ((x=10.0/3.0))[ksh]$printf "%.2f\n", $x3.00
the following example shows bc and awk, which are available in any shell
$echo 'scale = 2 ;10/3' | bc
3.33$awk 'BEGIN {printf "%.2f\n",10/3 ;}'3.33
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.