1

I have a float number of 1.000001f

I want to round it up to the next integer. In this case to 2.

How can I do that?

I tried Math.Floor, Math.Ceiling, Math.Round. Nothing works.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Johnny
  • 612
  • 3
  • 13
  • 32

1 Answers1

3

Shouldn't have an issue with this using Math.Ceiling

float precise = 1.000001f;

var roundedUp = (int)Math.Ceiling(precise); // 2: System.Int32

note - roundedUp will be of type System.Double without the (int) cast

.NET Fiddle - demo

scniro
  • 16,844
  • 8
  • 62
  • 106