Arithmetic but keep 2 decimal places

I am trying to perform arithmetric, for example, to increment the value of variable $a (say 3) by 0.05 but when I tried the following expression

let a=a+0.05

or

a=$((a+0.05))

both returned

3.0499999999999998

I want to keep 2 decimal places so it returns 3.05 instead.

a=$(echo "scale=2; 3+0.05" | bc)
echo 3 | awk '{print $0+0.05}'
3.05
a=$(echo $a | awk '{print $0+0.05}')

Hi.

printf "%s %.2f\n" $a $a
3.0499999999999998 3.05

Best wishes ... cheers, drl

This just clean up the mess not the source of the problem.
Using awk or bc and you get correct result.

It works on your system in your case but this is not guaranteed. It uses floating point numbers too, which have the same issues anywhere.

bc, being an arbitrary precision calculator, can indeed give you the exact result, though fiddling is necessary to prevent it stripping off the decimal points.

Thanks everyone!