Rounding decimals to interger

F

Franck

i would like to know how can i round to next greater than integer if
not integer already
what i mean is:

5.00000000000000000000000001 rounded to 6
5.1 rounded to 6
5.7 rounded to 6
6.0 rounded to 6
5.0 rounded to 5
as long as the value have something in decimal round it to the nearest
integer greater than
 
C

Christof Nordiek

Franck said:
i would like to know how can i round to next greater than integer if
not integer already
what i mean is:

5.00000000000000000000000001 rounded to 6
5.1 rounded to 6
5.7 rounded to 6
6.0 rounded to 6
5.0 rounded to 5
as long as the value have something in decimal round it to the nearest
integer greater than

use Math.Ceiling

Christof
 
F

Franck

use Math.Ceiling

Christof

Works. i was trying whit split and everything :p but the problem was
depending on country the decimal symbol can be a dot or a comma. that
ceilling simplyfied my life there
 
J

John Duval

i would like to know how can i round to next greater than integer if
not integer already
what i mean is:

5.00000000000000000000000001 rounded to 6
5.1 rounded to 6
5.7 rounded to 6
6.0 rounded to 6
5.0 rounded to 5
as long as the value have something in decimal round it to the nearest
integer greater than

Hi Franck,
You could use Math.Ceiling, like this:

decimal[] d = { 5.00000000000000000000000001M, 5.1M, 5.7M, 6.0M,
5.0M };
decimal[] d2 = new decimal[d.Length];
for (int i = 0; i < d.Length; i++)
d2 = Math.Ceiling(d);

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top