Thread: Small numbers

  1. #1
    Registered User
    Join Date
    Apr 2004

    Small numbers

    Hey guys,

    Been out of programming for a while and just started working on an app to calculate relative velocities of minor planets. But i ran into a probelm, when i create a double or a float and assign 24/360 to it, it returns zero instead of .066666 like it should. I'm sure i'm just doing something stupid here.

    Thanks a lot,

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Could be a problem related to type casting. Try using 24.0 / 360.0.

    When working with integers, no correct rounding occurs, you just lose the fractional portion completely. The compiler will interpret your code as dividing two integers, and so the result will be an integer - unless you do something like the above to change the division.

  3. #3
    Registered User
    Join Date
    Apr 2004
    ah, thanks, should have remembered that , but i guess that's what time does to you

  4. #4
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Also it might be a good idea to postfix floating point values with f

    24.0f / 360.0f
    What is C++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 08-18-2008, 05:31 PM
  2. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 09:15 PM
  3. Comparing numbers to a list of numbers held in a text file
    By jmajeremy in forum C++ Programming
    Replies: 3
    Last Post: 11-06-2006, 07:56 AM
  4. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  5. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM