Thread: problem with double format...

  1. #1
    Registered User
    Join Date
    Apr 2004

    Unhappy problem with double format...


    I have a question:
    How i can get double numbers from the keyboard?
    i.e:i want to assign in variable (double e the number 0.000001
    and the number 2 in variable (double a and number 1 in variable (double a)....

    Finally if i want to compare double formats
    i.e: if (((b-a)<e)) <---------this will occure an error?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Try the FAQ. Look into the %f format specifier if using scanf, or atof if using something like fgets. Also, floating point numbers aren't real great for specific comparisions. Your if check will most likely work. But there's a chance you'll get inaccurate precision with your floating point numbers which could potentially make what would normally be correct, incorrect results.

    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Actually, that depends on what he's trying to do...
    if he's doing the == comparison, then it's risky, very much so...
    but if he uses the fabs() function with it, such types of comparisons then become very useful for controlling the precision of values that you want to get...
    pretty use for engineering stuff actually...
    as such, the only recomendation I would have for him is to do this:
    when comparing differences, use fabs
    if ((fabs(b-a)<e))
    that way, you can compare differences without having to wonder about wheter will you get negative or positive differences.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  2. Compression/Decompression Wave File and MP3
    By cindy_16051988 in forum Projects and Job Recruitment
    Replies: 51
    Last Post: 04-29-2006, 06:25 AM
  3. Help with multi function progam
    By WackoWolf in forum C Programming
    Replies: 22
    Last Post: 10-13-2005, 02:56 AM
  4. Little Problem on Presentation in the Tower of Hanoi
    By momegao in forum C++ Programming
    Replies: 3
    Last Post: 04-20-2003, 06:22 PM
  5. getline problem
    By scottmanc in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2003, 09:27 PM