1

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?

4 Answers 4

11

Math.Ceiling

Sign up to request clarification or add additional context in comments.

Comments

1
dim rounded as int = Math.Ceiling(4.1)

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

Comments

0

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

Comments

0

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);
    }
}

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.