Consider the following simple division:
A=8.868; A/0.1 ans = 88.679999999999993
This results in a small error due to floating point precision. Is there any way to prevent this? Basically, all I do is move the comma by one position, not being close to the maximum number of allowed digits in MATLAB.
I would like to get the result as:
A/0.1 ans = 88.68
where trailing zeros don't matter unless they are zero and don't contain some number on the 14th digit or so.
Interestingly, this problem also appears when rounding to N digits:
R = (randi([8659 49847],[1e3 1]))/1e3; xmin = min(R); el = 0.1; step = 1/el; tmp1=xmin/el; tmp2=round(tmp1); tmp3=round(tmp2*el,3); tmp3 = 8.699999999999999
source share