# Rounding question

• 03-26-2011
george7378
Rounding question
Hi everyone,

I am doing a little project where I am trying to make a sunrise/sunset calculator using the equations on here:

Sunrise equation - Wikipedia, the free encyclopedia

In the 'complete calculation' part, there is a formula for Julian cycle where you calculate a value and then round it. I was wondering - how do you do this round(n*) function in C++? Is it the same as calculating n* and then just storing it as in integer?

Thanks.
• 03-26-2011
grumpy
Not quite. That link doesn't fully define the terms it uses but, in this case, my guess is that it is referring to nearest integer (whereas a straight conversion to an int rounds toward zero). For example, 24.4 would be rounded to 24, but 25.5 would be rounded to 25.

Look up the math function functions fmod(), floor(), and ceil(). You can use them in combination to do this type of rounding (assuming the value you start with is in the range of values supported by the int type).
• 03-27-2011
george7378
Hi - thanks for the response! I will look them up.