About the calculation precise

The precise of calculation has a problem when I add 60.425 with 0.425. The exact value should be 60.85, however I just got 60.8499999..., which affects my following calculation. How I can avoid such problem?

More Answers (1)

For your particular example, none of the values can be represented in IEEE double exactly:
>> num2strexact(60.425)
ans =
6.04249999999999971578290569595992565155029296875e1
>> num2strexact(0.425)
ans =
0.424999999999999988897769753748434595763683319091796875
>> num2strexact(60.425+0.425)
ans =
6.0849999999999994315658113919198513031005859375e1
You can find num2strexact here:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!