You are viewing a single comment's thread. Return to all comments →
Having the same issues as everyone else here; scale = 3 gives 17.928 NOT 17.929. Although I know that the answer should be 17.929, quite an odd problem.
scale = 3
You need to use the printf method for it to work, the reason is that -bc literally chops off the end of the number instead of actually rounding.
the actual answer is 17.9285 - which needs to be (upgraded) to 17.929
the reason why most people faltered is because they truncated rather than rounding off.
Would have been nice if there was an info on that in the problem description... bc -l is described in great detail and used but nowhere is it pointed out that it truncates, or that the problem would need proper roundings... pretty frustrating, as arithmetical rounding is hardly ever requested in CS problems and everybody is fine with truncating...
echo $num | bc -l | xargs printf "%.*f\n" 3