Cannot subtract number of order smaller then e-4 from variable
38 views (last 30 days)
Show older comments
Dominik Stolfa
on 26 Nov 2024 at 19:14
Commented: Dominik Stolfa
on 26 Nov 2024 at 21:08
a=0.1; a=a-1e-5 gives result a=0.1000
0 Comments
Accepted Answer
Torsten
on 26 Nov 2024 at 19:20
Edited: Torsten
on 26 Nov 2024 at 19:21
It's just a question of how the numbers are displayed.
Internally, the precision of computing is much higher.
format long % Use display format long
a = 0.1;
a = a - 1e-5
format short
a
3 Comments
Walter Roberson
on 26 Nov 2024 at 20:18
Edited: Walter Roberson
on 26 Nov 2024 at 20:26
format long % Use display format long
a = 0.1;
fprintf('%.999g\n', a)
a = a - 1e-5
fprintf('%.999g\n', a)
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!