views:

223

answers:

4

I need your help,

For example I have a decimal type variable and I want to round up this way.

Eg

3.0 = 3

3.1 = 4

3.2 = 4

3.3 = 4

3.4 = 4

3.5 = 4

3.6 = 4

3.7 = 4

3.8 = 4

3.9 = 4

4.0 = 4

4.1 = 5

4.2 = 5

etc....

How can I do that?

+10  A: 

Math.Ceiling

Otávio Décio
Your geniuuuuuuosouuosuosuosuos!!! :) Thanks Mate
David Bonnici
Click on the tick to accept the answer...
Jon Skeet
+1  A: 
dim rounded as int = Math.Ceiling(4.1)

(a bit rusty on the VB syntax, so it may not be in perfect, compilable syntax)

Andreas Grech
A: 

maybe you must parse to char and desimal value must be check... a=3.4 stra=cstr(a) b=substring(stra,0,1) c=substring(stra,2,1)

d=cint(c) e=cint(b)

if d>0 then e+=1 end if

A: 

Very Simple, the trick is the Ceiling function provided by most of the programming. For instance in C#, it is a staic method inside the Math namespace;

namespace ConsoleDebugger { class Program { static void Main(string[] args) { int lowerLimit = 3; int upperLimit = 10;

        int index = 0;
        for (int i = lowerLimit; i < upperLimit; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                string value = i + "." + j;
                Console.WriteLine( value + "  " + Round(double.Parse(value)));
            }

            if (index == 10)
                index = 0;
        }
        Console.ReadLine();
    }

    private static double Round(double number)
    {
        return Math.Ceiling(number);
    }
}

}

Shiva