Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round a decimal up?

Tags:

c#

.net

rounding

Given a decimal '96.154', how can I ensure that it is always rounded up to 96.16 (as opposed to normal rounding to 2 decimals which would give 96.15).

like image 367
Adam Goss Avatar asked Aug 03 '12 11:08

Adam Goss


2 Answers

Kind of hacky but a very intuitive way to do so:

var val = 96.154M;

var result = Math.Ceiling(val * 100) / 100.0M;
like image 125
Yuck Avatar answered Oct 26 '22 23:10

Yuck


You can add 0.005 to the value and then round the result.

like image 37
Bruno Ferreira Avatar answered Oct 26 '22 23:10

Bruno Ferreira