views:

30

answers:

1

consider ,

object a =1.123456;
float f = convert.ToSingle(a);

But when I print the value of f , I get 1.123455.

It is getting rounded off. Also the problem is I cant change the data type of float in the code. Please help.

+1  A: 

This is done because of the way the floating-point type works. If you want a better precision (in the cost of some performance) - use the Double or Decimal type instead.

For more information about why floating-point loses precision, read: http://msdn.microsoft.com/en-us/library/c151dt3s%28VS.80%29.aspx

Nissim