I have a string which represents a floating-point number. When i try to convert it to float number i don't get the exact floating point number. my example code is given below.
string s_num = "666890.23"
float f_num = float.Parse(s_num);
The result is f_num = 666890.25
Why is this happening. Why am I not getting the exact figure.
Please help me out.
Converting string to float in C#
Page 1 of 13 Replies - 82654 Views - Last Post: 19 April 2010 - 12:23 AM
Replies To: Converting string to float in C#
#2
Re: Converting string to float in C#
Posted 22 December 2006 - 12:13 AM
use System.Convert.ToDouble(s_num) and change float to double...
#18
Re: Converting string to float in C#
Posted 24 December 2006 - 12:38 PM
according to this website floats in C# are only Precise to 7 digits
C# Float
if you were to do something like
string s_num = "66690.23"
float f_num = float.Parse(s_num);
The result is f_num = 66690.23
it is better to just use double. Less problems
double.Parse(s_num);
hope that helps
C# Float
if you were to do something like
string s_num = "66690.23"
float f_num = float.Parse(s_num);
The result is f_num = 66690.23
it is better to just use double. Less problems
double.Parse(s_num);
hope that helps
This post has been edited by unreal_origin: 24 December 2006 - 12:50 PM
#19 Guest_shift*
Re: Converting string to float in C#
Posted 19 April 2010 - 12:23 AM
thanx it worked
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote


|