Need Help With Floats.....

This is a discussion on Need Help With Floats..... within the C Programming forums, part of the General Programming Boards category; Hi friends, I need help with the floating point numbers. Actually, I want all the calculations done involving floats to ...

  1. #1
    Unregistered
    Guest

    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.
    Thanks,
    Sriharsha.

    My Email ID: vsriharsha@rediffmail.com

  2. #2
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77
    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 quit.....no one else made suggestions so i tried...

  3. #3
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77
    OK...so 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 ATOI.....now 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, 03: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, 10:41 PM
  4. comparing two arrays of floats
    By COBOL2C++ in forum C++ Programming
    Replies: 7
    Last Post: 07-16-2003, 04:22 AM
  5. Using floats in conditional statements
    By DBB in forum C++ Programming
    Replies: 3
    Last Post: 09-12-2001, 08:54 AM

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