|
| weird problems with float and double : Why 262.4 - 313.83 = -51.4299927 ? |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.general.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Matthieu Tudury |
Hi, i got a weird problem with decimal numbers,
Here is a test sample :
float a, b, c; double da, db, dc;
da = 313.83; db = 262.4; dc = db -da;
a = (float)da; b = (float)db; c = b - a;
Console.WriteLine(c.ToString()); Console.WriteLine(dc.ToString());
DataSet ds = new DataSet(); ds.Tables.Add("titi"); ds.Tables[0].Columns.Add("number",typeof(float)); ds.Tables[0].Columns.Add("number2",typeof(double)); DataRow dr = ds.Tables[0].NewRow();
dr[0] = c; dr[1] = dc; ds.Tables[0].Rows.Add(dr);
Console.WriteLine(ds.GetXml());
and the result :
-51,42999 -51,43 <NewDataSet> <titi> <number>-51.4299927</number> <number2>-51.430000000000007</number2> </titi> </NewDataSet>
If Someone can help me solve this problem...
Thanks
|
|
|
| |
|
| |
| | |
| | |
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|