views:

149

answers:

3

Hi, this is probably the really newbie question (well, I'm pretty sure it is), but I have a float that's being returned and I need a quick and efficient way of turning it into an int.

Pretty simple, but I have an exception. If the remainder of the float is anything other than .0 then I want to increment the int.

Some quick examples:

Float = 98.0, Int = 98
Float = 98.1, Int = 99
Float = 6.6, Int = 7
etc.

Thanks for any help!

+12  A: 

This should do it:

int myInt = (int)Math.Ceiling(myFloat);
Dan Tao
Thanks so much!
Django Reinhardt
+4  A: 

Use

Math.Ceiling();

as Math.Round() won't make 98.1 equal to 99

JTA
+1  A: 

Convert.ToInt32(Math.Ceiling(FloatValue));

Sunil