Thread: Rounding question

  1. #1
    george7378
    Guest

    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.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    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).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    george7378
    Guest
    Hi - thanks for the response! I will look them up.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question about a question
    By hausburn in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2010, 05:24 AM
  2. SDL buffer channels question
    By TriKri in forum Game Programming
    Replies: 3
    Last Post: 12-09-2009, 05:52 PM
  3. Newbie question, C #
    By mate222 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2009, 06:24 AM
  4. rounding question
    By keithmolo in forum C++ Programming
    Replies: 12
    Last Post: 08-14-2003, 08:33 AM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM