Single.Parse(999999999) = 1.0E+8 (100000000.00) ???

Hi.......

Quote:

Single.MaxValue = 340282300000000000000000000000000000000.00

When trying to parse a value like 99999999 to single, it gives me 1.0E+8 (100000000.00). This is not i was expecting and ofcourse no one would.....How to resolve this type of problem. I cannot (now) go for double coz its already late. I even tried Convert.ToSingle and Ctype way but all yielded the same result .

Please help me out of this...



Answer this question

Single.Parse(999999999) = 1.0E+8 (100000000.00) ???

  • Visions.net

    It has to do with the precision of doubles and singles:

    Dim i As Integer = 999999999

    Dim sngl As Single = Single.Parse(i)

    Dim dbl As Double = Double.Parse(i)

    Debug.Print(i)

    Debug.Print(sngl)

    Debug.Print(dbl)

    Results

    999999999

    1E+09

    999999999

    What are you actually trying to accomplish



  • Kingsonal

    Unfortunately there is no good way out of this. While Single's have a big range of numbers they can represent, they cannot represent every number in that range. In many ways Single's are an approximation of a number.

    If you want 100% accuracy you're going to have to use the Decimal type.



  • Bill Reiss

    Hai DMan1,

    I was testing my application with huge values and one such value is 999999999. After updating, i saw the result which i was not expecting. So if anyone has come over this issue and resolved, then please let us know.

    Regards,



  • Single.Parse(999999999) = 1.0E+8 (100000000.00) ???