Jump to content

floating point variables in c/c++

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
avibiter

avibiter

    Newbie

  • Members
  • Pip
  • 5 posts
hello
i've read a bit about floating point numbers,
i saw the you can't represent the number 0.1 as a floating point number (at least not as a finite one)
but when i tried in visual studio 2008 to assign the value 0.1 to a float variable it shows in the watch window that the value is 0.1
any one know why?
thank you

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Whenever you convert between the binary and decimal representation, rounding occurs. The decimal representation may be 0.0999999999999999999999875 which rounds to 0.1 when on 10 decimal places are converted, or something similar.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog