|
-
July 6th, 2012, 02:42 AM
#1
Trouble converting string to double
Hello,
I have trouble in converting string to double. I am using following code:
Code:
float[] aData = new float[0];
aData[0] = System.Convert.ToSingle(s.ToString(), CultureInfo.CurrentUICulture); /** doesn't matter if I use Culture info or not */
//or
float.TryParse(s.ToString(), NumberStyles.AllowDecimalPoint, CultureInfo.CurrentUICulture, out aData[0]);
If my string is 123.56 then output in aData[0] (followed in memory) is 123.560000000000003. I do not know from where I am getting 3 in the end. It is sometimes 1, sometimes 2 etc. The best example I could find was: if the input string is 981.55, the coversion to double results in 981.54999999999995
Any hint how can I correct it?
Regards
Ricky
Last edited by ricky_cpp; July 6th, 2012 at 03:27 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|