Rounding question

This is a discussion on Rounding question within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I am doing a little project where I am trying to make a sunrise/sunset calculator using the equations ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    128

    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,658
    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, Sunshine, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    128
    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, 06: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, 09:33 AM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21