English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

e.g: 232.345 & 232.347 are same upto 2 decimial points but, 223.567 & 345.567 are not same.
plz help!

2006-12-10 02:32:46 · 3 answers · asked by sweety 2 in Computers & Internet Programming & Design

3 answers

You don't want to do floating point comparisons...

Multiply each float by 100. Then insert each float into a long. The effect is truncating the decimal portion. Compare the two longs...

2006-12-10 02:59:31 · answer #1 · answered by csanon 6 · 0 0

As you've not informed the language you're engaged on so i am going to easily inform you an elementary theory a thanks to do it. convert both the values to characters (C++) or strings(JAVA). Char/String elements a lot of purposes to get rid of letters from it, once you've performed that Convert it decrease back into floating element. And there you're only do the easy examine to ensure in the journey that they are equivalent or not! There are another ideas also yet i imagine this one is in elementary words one thanks to do it.

2016-11-30 09:38:00 · answer #2 · answered by ? 4 · 0 0

#ifndef FALSE
    #define FALSE 0
#endif

#ifndef TRUE
    #define TRUE 1
#endif

const double EPSILON = 0.01; // change this for more or less accuracy
unsigned short sameNumber(double x, double y)
{
    if ((x - y) < EPSILON)
        return TRUE;
    else
        return FALSE;
}

2006-12-10 12:35:05 · answer #3 · answered by simguru 2 · 0 0

fedest.com, questions and answers