Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

How does someone mathematically round a number to its nearest integer?

For example 1.2 would round down to 1 and 1.7 would round up to 2

share|improve this question
    
Are you asking for an algorithm to round the number? –  Chao Xu Jan 13 '11 at 18:37

2 Answers 2

up vote 5 down vote accepted

You could use the "ceiling-function / floor-function" which always rounds an integer up/down ( http://en.wikipedia.org/wiki/Floor_and_ceiling_functions ).

If you want the number to be rounded the way you want you could just do

$\text{round}(x)= \lceil x-\frac{1}{2} \rceil$ Note that in this case $\text{round}(1.5)=1$

Or $\text{round'}(x)= \lfloor x+\frac{1}{2} \rfloor$ Note that in this case $\text{round'}(1.5)=2$

share|improve this answer
    
round' is what I was after. I didn't know that floor and ceiling functions exists in mathematical syntax –  BHare Jan 13 '11 at 18:46
2  
@BHare: in «mathematical syntax» everything you can come up with exists. –  Mariano Suárez-Alvarez Jan 14 '11 at 0:39

This is equivalent to looking at the floor and ceiling functions. See this. In particular, rounding a number $y$ to an integer $q$ is the same thing as looking as $q = \text{floor}(y)$ or $q = \text{ceil}(y)$.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.