The diagnosis of the other answers is correct, but the prognosis is not the best. The simplest way, and I would say more correct because it avoids conversion, to do this is so:
decimal arrendondamento = contrato.Count / 50M;
var valorArredondado = Math.Ceiling(arrendondamento);
In this way you have a number as decimal and the division occurs respecting it without having to convert anything that is inefficient and verbose. Note that the problem is the typing in the division, the rounding method does not interfere with this, so I made a code that shows the result without applying it too:
using static System.Console;
using static System.Math;
public class Program {
public static void Main() {
var contador = 63;
decimal arrendondamento = contador / 50M;
WriteLine(arrendondamento);
WriteLine(Ceiling(arrendondamento));
}
}
Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.
But to round off to 2 the value should not be greater than 1.50?
– Deividson Oliveira
So that’s why I need to check, because it always needs to be up.
– Mariana
1.01 would also stay 2? 1.00 would stay 1 right?
– Focos
That’s it. Because I need to generate a batch, if 1.01 means you still have something to generate, and so it needs to be up.
– Mariana
A the result of 2 integer numbers is always an integer number. Tries to convert the numbers to decimal and checks the return.
– Deividson Oliveira