Thread: Need Help With Floats.....

  1. #1

    Angry Need Help With Floats.....

    Hi friends,
    I need help with the floating point numbers. Actually, I want all the calculations done involving floats to be done using 2/3 digit precision. For Example... if I enter
    a=20.20 and b=30.30 and then say c=b-a
    internally a=20.200001 and b=30.299999 and accordingly c is not exactly equal to 10.10.
    I need a way out with this.
    The answers can be corrected in PRINTF using the format specifier but I dont Use Printf in my programs (low level).
    Please help me out with this.

    My Email ID:

  2. #2
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    mmm....well i can offer a crazy idea.........maybe it won't work since you are programming low level or whatever.....could you make the number a string.....parse the data at the "." (period).....grab 2 characters past the period...throw the first digits plus a period back with the 2 characters grabbed....then store in back to a float? or will that still jack things up? i wrote some code for awhile...but its past 4am and it wasnt working right so i one else made suggestions so i tried...

  3. #3
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    77 that didn't work...What if you did that...broke it up into 2 strings...the first digits (up to the decimal place)....then the 2 digits after the decimal place.....Convert those to INT, not FLOAT....just go do your math with the integers.....then throw the numbers back together as a float........get my drift?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. variables larger than floats
    By a.mlw.walker in forum C Programming
    Replies: 13
    Last Post: 04-23-2009, 02:28 AM
  2. Reading errors in floats
    By Improvolone in forum C++ Programming
    Replies: 8
    Last Post: 03-21-2006, 03:20 PM
  3. % and floats
    By confuted in forum C++ Programming
    Replies: 2
    Last Post: 08-04-2003, 09:41 PM
  4. comparing two arrays of floats
    By COBOL2C++ in forum C++ Programming
    Replies: 7
    Last Post: 07-16-2003, 03:22 AM
  5. Using floats in conditional statements
    By DBB in forum C++ Programming
    Replies: 3
    Last Post: 09-12-2001, 07:54 AM