Results 1 to 2 of 2
This is puzzling me.
$ x=165
$ printf "%2.1f\n" $[$x/10]
16.0
The result is 16.0 instead of 16.5.
If I put
$ printf "%2.1f\n" $[$x/10.0]
bash: 165/10.0: syntax error: invalid ...
- 05-16-2011 #1Just Joined!
- Join Date
- May 2011
- Posts
- 2
Need help with printf in bash shell
This is puzzling me.
$ x=165
$ printf "%2.1f\n" $[$x/10]
16.0
The result is 16.0 instead of 16.5.
If I put
$ printf "%2.1f\n" $[$x/10.0]
bash: 165/10.0: syntax error: invalid arithmetic operator (error token is ".0")
So what should I do to get the correct result, which is 16.5?
- 05-17-2011 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
welcome to the forum
because '/' truncates the quotient, you need to
pick up the remainder: like this
printf "%2.1f\n" $[$x/10].$[$x%10]the sun is new every day (heraclitus)


Reply With Quote