Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round up in c#

Tags:

c#

rounding

I want to round up always in c#, so for example, from 6.88 to 7, from 1.02 to 2, etc.

How can I do that?

like image 956
Scott Avatar asked Apr 10 '11 17:04

Scott


People also ask

Does C programming round up or down?

Integer division truncates in C, yes. (i.e. it's round towards zero, not round down.) round toward 0 meaning . 5 or greater => round up 0 to .

How do you round down in C?

In the C Programming Language, the floor function returns the largest integer that is smaller than or equal to x (ie: rounds downs the nearest integer).

What does Ceil () do in C?

C ceil() The ceil() function computes the nearest integer greater than the argument passed.


2 Answers

Use Math.Ceiling()

double result = Math.Ceiling(1.02); 
like image 187
BrokenGlass Avatar answered Sep 23 '22 16:09

BrokenGlass


Use Math.Ceiling: Math.Ceiling(value)

like image 28
Talljoe Avatar answered Sep 19 '22 16:09

Talljoe