This should be easy, but I can’t find a built in method for it, the .net framework must have a method to do this!
private decimal RoundDownTo2DecimalPlaces(decimal input)
{
if (input < 0)
{
throw new Exception("not tested with negitive numbers");
}
// There must be a better way!
return Math.Truncate(input * 100) / 100;
}
Round(temp, 2);
Round(Decimal) Method. This method is used to round a decimal value to the nearest integer. Syntax: public static decimal Round (decimal d); Here, it takes a decimal number to round.
Math.Floor(number * 100) / 100;
If you are rounding down then you need:
Math.Floor(number * 100) / 100;
if you are looking for something called 'bankers rounding' (probably not if it's for output and not for statistics/summing) then:
Math.Round(number, 2);
Finally if you want, not sure what the correct term is, 'normal rounding':
Math.Round(number, 2, MidpointRounding.AwayFromZero);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With