- http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F and read
- Cleve's piece
sprintf('%d',x) prints out exponential notation instead of decimal notation
357 views (last 30 days)
Jeffrey Wildman on 26 Aug 2014
I am using version '184.108.40.2062 (R2014a)'. The sprintf command seems to print out exponential notation when decimal notation is requested (second and third example):
ans = 105
ans = 1.100000e+02
ans = 1e+02
Is there any reason why the last two calls are not printing '110'?
per isakson on 26 Aug 2014
Edited: per isakson on 26 Aug 2014
What you see is a consequence of how floating point arithmetic works.
1.05*100 evaluates to a whole number (flint). The other two don't.
More Answers (2)
Andrew Reibold on 26 Aug 2014
Edited: Andrew Reibold on 26 Aug 2014
Use f instead of d for floating point notation will stop the scientific I believe.
ans = 105.000000
ans = 110.000000
ans = 110
Notice I can stop the decimals by using .0f like I did in the last example.
For additional reference: