Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:48 AM
kkmigas@gmail.com
 
Posts: n/a
Default Math BUG??

Can some one plz explain this???

SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2);

Linux (Servidor Mysql 4)

20.04 | 20.04

Windows (Servidor Mysql 4)

20.05 | 20.05

Thanks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 08:49 AM
Lee Peedin
 
Posts: n/a
Default Re: Math BUG??

On 21 Dec 2006 07:03:22 -0800, "kkmigas@gmail.com" <kkmigas@gmail.com>
wrote:

>Can some one plz explain this???
>
>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2);
>
>Linux (Servidor Mysql 4)
>
>20.04 | 20.04
>
> Windows (Servidor Mysql 4)
>
>20.05 | 20.05
>
>Thanks



Here's my results of:
SELECT VERSION();
SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2)

Linux
5.0.24a
20.45000 | 20.05

Windows
5.0.24-community-nt
20.45000 | 20.05

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 08:49 AM
Brian Wakem
 
Posts: n/a
Default Re: Math BUG??

Lee Peedin wrote:

> On 21 Dec 2006 07:03:22 -0800, "kkmigas@gmail.com" <kkmigas@gmail.com>
> wrote:
>
>>Can some one plz explain this???
>>
>>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2);
>>
>>Linux (Servidor Mysql 4)
>>
>>20.04 | 20.04
>>
>> Windows (Servidor Mysql 4)
>>
>>20.05 | 20.05
>>
>>Thanks

>
>
> Here's my results of:
> SELECT VERSION();
> SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2)
>
> Linux
> 5.0.24a
> 20.45000 | 20.05
>
> Windows
> 5.0.24-community-nt
> 20.45000 | 20.05



Linux 4.1.16
20.04 | 20.04

Linux 5.0.24-standard-log
20.045000 | 20.05


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 08:49 AM
kkmigas@gmail.com
 
Posts: n/a
Default Re: Math BUG??

Using the command with version heres the outputs
SELECT VERSION( ) , (( 200.45 *1 ) * ( 10 /100 )), ROUND( ( 200.45 *1 *
( 10 /100 ) ) , 2 ) , ROUND( 20.045, 2 ) ;

Windows 2003
5.0.22-community-nt 20.045000 20.05 20.05

Windows 2003
4.1.18-nt-max 20.05 20.05 20.05

Centos
4.1.21-standard 20.04 20.04 20.05

FreeBSD
3.23.58 20.05 20.05 20.05

After all my testing i've found that the only system that does the
Round and the math good is windows.


On Dec 22, 6:03 pm, Brian Wakem <n...@email.com> wrote:
> Lee Peedin wrote:
> > On 21 Dec 2006 07:03:22 -0800, "kkmi...@gmail.com" <kkmi...@gmail.com>
> > wrote:

>
> >>Can some one plz explain this???

>
> >>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2);

>
> >>Linux (Servidor Mysql 4)

>
> >>20.04 | 20.04

>
> >> Windows (Servidor Mysql 4)

>
> >>20.05 | 20.05

>
> >>Thanks

>
> > Here's my results of:
> > SELECT VERSION();
> > SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2)

>
> > Linux
> > 5.0.24a
> > 20.45000 | 20.05

>
> > Windows
> > 5.0.24-community-nt
> > 20.45000 | 20.05Linux 4.1.16

> 20.04 | 20.04
>
> Linux 5.0.24-standard-log
> 20.045000 | 20.05
>
> --
> Brian Wakem
> Email:http://homepage.ntlworld.com/b.wakem/myemail.png


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 08:49 AM
kkmigas@gmail.com
 
Posts: n/a
Default Re: Math BUG??

It must be something with the libs im using on the background can any
one tell me witch ones do i need to change or point me to some website
that explains / solves this problem.

On Dec 26, 11:32 am, "kkmi...@gmail.com" <kkmi...@gmail.com> wrote:
> Using the command with version heres the outputs
> SELECT VERSION( ) , (( 200.45 *1 ) * ( 10 /100 )), ROUND( ( 200.45 *1 *
> ( 10 /100 ) ) , 2 ) , ROUND( 20.045, 2 ) ;
>
> Windows 2003
> 5.0.22-community-nt 20.045000 20.05 20.05
>
> Windows 2003
> 4.1.18-nt-max 20.05 20.05 20.05
>
> Centos
> 4.1.21-standard 20.04 20.04 20.05
>
> FreeBSD
> 3.23.58 20.05 20.05 20.05
>
> After all my testing i've found that the only system that does the
> Round and the math good is windows.
>
> On Dec 22, 6:03 pm, Brian Wakem <n...@email.com> wrote:
>
> > Lee Peedin wrote:
> > > On 21 Dec 2006 07:03:22 -0800, "kkmi...@gmail.com" <kkmi...@gmail.com>
> > > wrote:

>
> > >>Can some one plz explain this???

>
> > >>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2);

>
> > >>Linux (Servidor Mysql 4)

>
> > >>20.04 | 20.04

>
> > >> Windows (Servidor Mysql 4)

>
> > >>20.05 | 20.05

>
> > >>Thanks

>
> > > Here's my results of:
> > > SELECT VERSION();
> > > SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2)

>
> > > Linux
> > > 5.0.24a
> > > 20.45000 | 20.05

>
> > > Windows
> > > 5.0.24-community-nt
> > > 20.45000 | 20.05Linux 4.1.16

> > 20.04 | 20.04

>
> > Linux 5.0.24-standard-log
> > 20.045000 | 20.05

>
> > --
> > Brian Wakem
> > Email:http://homepage.ntlworld.com/b.wakem/myemail.png


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 08:49 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Math BUG??

kkmigas@gmail.com wrote:
> It must be something with the libs im using on the background can any
> one tell me witch ones do i need to change or point me to some website
> that explains / solves this problem.
>
> On Dec 26, 11:32 am, "kkmi...@gmail.com" <kkmi...@gmail.com> wrote:
>
>>Using the command with version heres the outputs
>>SELECT VERSION( ) , (( 200.45 *1 ) * ( 10 /100 )), ROUND( ( 200.45 *1 *
>>( 10 /100 ) ) , 2 ) , ROUND( 20.045, 2 ) ;
>>
>>Windows 2003
>>5.0.22-community-nt 20.045000 20.05 20.05
>>
>>Windows 2003
>>4.1.18-nt-max 20.05 20.05 20.05
>>
>>Centos
>>4.1.21-standard 20.04 20.04 20.05
>>
>>FreeBSD
>>3.23.58 20.05 20.05 20.05
>>
>>After all my testing i've found that the only system that does the
>>Round and the math good is windows.
>>
>>On Dec 22, 6:03 pm, Brian Wakem <n...@email.com> wrote:
>>
>>
>>>Lee Peedin wrote:
>>>
>>>>On 21 Dec 2006 07:03:22 -0800, "kkmi...@gmail.com" <kkmi...@gmail.com>
>>>>wrote:

>>
>>>>>Can some one plz explain this???

>>
>>>>>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2);

>>
>>>>>Linux (Servidor Mysql 4)

>>
>>>>>20.04 | 20.04

>>
>>>>>Windows (Servidor Mysql 4)

>>
>>>>>20.05 | 20.05

>>
>>>>>Thanks

>>
>>>>Here's my results of:
>>>>SELECT VERSION();
>>>>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2)

>>
>>>>Linux
>>>>5.0.24a
>>>>20.45000 | 20.05

>>
>>>>Windows
>>>>5.0.24-community-nt
>>>>20.45000 | 20.05Linux 4.1.16
>>>
>>>20.04 | 20.04

>>
>>>Linux 5.0.24-standard-log
>>>20.045000 | 20.05

>>
>>>--
>>>Brian Wakem
>>>Email:http://homepage.ntlworld.com/b.wakem/myemail.png

>
>


It's not a a "problem" - it's how floating point numbers are stored, and
the results for your operation will always be somewhat unpredictable.
That's true not only in SQL - but in any language which uses floating
point numbers.

The reason this happens is that 20.045 is not exactly 20.045. If you
print it out to enough decimal places, it will come out to something
like 20.04499999967. Rounding this value would (correctly) give a
result of 20.04.

The same thing happens in decimal if you try adding 1/3 3 times. You
get .9999999... instead of 1 because 1/3 cannot be expressed directly in
decimal form.

The way to resolve it is to add a small value (smaller than the rounding
error) to the number. In your case a value of .001 should suffice
(since you're rounding to 2 decimal places).


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 08:49 AM
kkmigas@gmail.com
 
Posts: n/a
Default Re: Math BUG??

Any calculator is able to return the same value has the above.

The so special calc that i am making is quite simple.

200.45 is the price
1 = quantity
10 is the discount

((200.45 * 1) * (10/100))
Price * Qt. * (Discount/100)

I am trying to get how much is the Discount in Price * Qt.

200.45 * 10% gives very simple result ( 200.45 * 0.10 ) = 20.045

the only Mysql Servers that returns the right value are
5.0.22-community-nt 20.045000 20.05 20.05
5.0.22-standard 20.045000 20.05 20.05

After all my tests it seems that i am going to mysql 5 sooner than
expected since it does all the math correctly.

Thanks for all the help. Hope this can also helps someone else.
Best Regards
Luis Miguel Freitas

On Dec 26, 2:22 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> kkmi...@gmail.com wrote:
> > It must be something with the libs im using on the background can any
> > one tell me witch ones do i need to change or point me to some website
> > that explains / solves this problem.

>
> > On Dec 26, 11:32 am, "kkmi...@gmail.com" <kkmi...@gmail.com> wrote:

>
> >>Using the command with version heres the outputs
> >>SELECT VERSION( ) , (( 200.45 *1 ) * ( 10 /100 )), ROUND( ( 200.45 *1 *
> >>( 10 /100 ) ) , 2 ) , ROUND( 20.045, 2 ) ;

>
> >>Windows 2003
> >>5.0.22-community-nt 20.045000 20.05 20.05

>
> >>Windows 2003
> >>4.1.18-nt-max 20.05 20.05 20.05

>
> >>Centos
> >>4.1.21-standard 20.04 20.04 20.05

>
> >>FreeBSD
> >>3.23.58 20.05 20.05 20.05

>
> >>After all my testing i've found that the only system that does the
> >>Round and the math good is windows.

>
> >>On Dec 22, 6:03 pm, Brian Wakem <n...@email.com> wrote:

>
> >>>Lee Peedin wrote:

>
> >>>>On 21 Dec 2006 07:03:22 -0800, "kkmi...@gmail.com" <kkmi...@gmail.com>
> >>>>wrote:

>
> >>>>>Can some one plz explain this???

>
> >>>>>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2);

>
> >>>>>Linux (Servidor Mysql 4)

>
> >>>>>20.04 | 20.04

>
> >>>>>Windows (Servidor Mysql 4)

>
> >>>>>20.05 | 20.05

>
> >>>>>Thanks

>
> >>>>Here's my results of:
> >>>>SELECT VERSION();
> >>>>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2)

>
> >>>>Linux
> >>>>5.0.24a
> >>>>20.45000 | 20.05

>
> >>>>Windows
> >>>>5.0.24-community-nt
> >>>>20.45000 | 20.05Linux 4.1.16

>
> >>>20.04 | 20.04

>
> >>>Linux 5.0.24-standard-log
> >>>20.045000 | 20.05

>
> >>>--
> >>>Brian Wakem
> >>>Email:http://homepage.ntlworld.com/b.wakem/myemail.pngIt's not a a "problem" - it's how floating point numbers are stored, and

> the results for your operation will always be somewhat unpredictable.
> That's true not only in SQL - but in any language which uses floating
> point numbers.
>
> The reason this happens is that 20.045 is not exactly 20.045. If you
> print it out to enough decimal places, it will come out to something
> like 20.04499999967. Rounding this value would (correctly) give a
> result of 20.04.
>
> The same thing happens in decimal if you try adding 1/3 3 times. You
> get .9999999... instead of 1 because 1/3 cannot be expressed directly in
> decimal form.
>
> The way to resolve it is to add a small value (smaller than the rounding
> error) to the number. In your case a value of .001 should suffice
> (since you're rounding to 2 decimal places).
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 08:49 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Math BUG??

kkmigas@gmail.com wrote:
> On Dec 26, 2:22 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>
>>kkmi...@gmail.com wrote:
>>
>>>It must be something with the libs im using on the background can any
>>>one tell me witch ones do i need to change or point me to some website
>>>that explains / solves this problem.

>>
>>>On Dec 26, 11:32 am, "kkmi...@gmail.com" <kkmi...@gmail.com> wrote:

>>
>>>>Using the command with version heres the outputs
>>>>SELECT VERSION( ) , (( 200.45 *1 ) * ( 10 /100 )), ROUND( ( 200.45 *1 *
>>>>( 10 /100 ) ) , 2 ) , ROUND( 20.045, 2 ) ;

>>
>>>>Windows 2003
>>>>5.0.22-community-nt 20.045000 20.05 20.05

>>
>>>>Windows 2003
>>>>4.1.18-nt-max 20.05 20.05 20.05

>>
>>>>Centos
>>>>4.1.21-standard 20.04 20.04 20.05

>>
>>>>FreeBSD
>>>>3.23.58 20.05 20.05 20.05

>>
>>>>After all my testing i've found that the only system that does the
>>>>Round and the math good is windows.

>>
>>>>On Dec 22, 6:03 pm, Brian Wakem <n...@email.com> wrote:

>>
>>>>>Lee Peedin wrote:

>>
>>>>>>On 21 Dec 2006 07:03:22 -0800, "kkmi...@gmail.com" <kkmi...@gmail.com>
>>>>>>wrote:

>>
>>>>>>>Can some one plz explain this???

>>
>>>>>>>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2);

>>
>>>>>>>Linux (Servidor Mysql 4)

>>
>>>>>>>20.04 | 20.04

>>
>>>>>>>Windows (Servidor Mysql 4)

>>
>>>>>>>20.05 | 20.05

>>
>>>>>>>Thanks

>>
>>>>>>Here's my results of:
>>>>>>SELECT VERSION();
>>>>>>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2)

>>
>>>>>>Linux
>>>>>>5.0.24a
>>>>>>20.45000 | 20.05

>>
>>>>>>Windows
>>>>>>5.0.24-community-nt
>>>>>>20.45000 | 20.05Linux 4.1.16

>>
>>>>>20.04 | 20.04

>>
>>>>>Linux 5.0.24-standard-log
>>>>>20.045000 | 20.05

>>
>>>>>--
>>>>>Brian Wakem
>>>>>Email:http://homepage.ntlworld.com/b.wakem/myemail.pngIt's not a a "problem" - it's how floating point numbers are stored, and

>>
>>the results for your operation will always be somewhat unpredictable.
>>That's true not only in SQL - but in any language which uses floating
>>point numbers.
>>
>>The reason this happens is that 20.045 is not exactly 20.045. If you
>>print it out to enough decimal places, it will come out to something
>>like 20.04499999967. Rounding this value would (correctly) give a
>>result of 20.04.
>>
>>The same thing happens in decimal if you try adding 1/3 3 times. You
>>get .9999999... instead of 1 because 1/3 cannot be expressed directly in
>>decimal form.
>>
>>The way to resolve it is to add a small value (smaller than the rounding
>>error) to the number. In your case a value of .001 should suffice
>>(since you're rounding to 2 decimal places).
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstuck...@attglobal.net
>>==================

>
>
> Any calculator is able to return the same value has the above.
>
> The so special calc that i am making is quite simple.
>
> 200.45 is the price
> 1 = quantity
> 10 is the discount
>
> ((200.45 * 1) * (10/100))
> Price * Qt. * (Discount/100)
>
> I am trying to get how much is the Discount in Price * Qt.
>
> 200.45 * 10% gives very simple result ( 200.45 * 0.10 ) = 20.045
>
> the only Mysql Servers that returns the right value are
> 5.0.22-community-nt 20.045000 20.05 20.05
> 5.0.22-standard 20.045000 20.05 20.05
>
> After all my tests it seems that i am going to mysql 5 sooner than
> expected since it does all the math correctly.
>
> Thanks for all the help. Hope this can also helps someone else.
> Best Regards
> Luis Miguel Freitas
>


(Top posting fixed)

"Any calculator" is not the same as a computer. This problem has
existed since the dawn of computing - I first saw it when I started with
Fortran in 1967. That's why there are DECIMAL data types - the data is
internally stored in a different format, which does have exact decimal
values.

But floating point values all suffer this problem - in all computers,
big and small.

And yes, you might have seen a version of MySQL 5.0 which "solves" this
problem - but it is not a "guaranteed" fix, because it's not a
"problem". ANY time you round as closely as you are doing, the results
will be indeterminate. The same is true with truncating;

0.2 * 5 does not necessarily equal 1.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-28-2008, 08:49 AM
Dennis K.
 
Posts: n/a
Default Re: Math BUG??

On 26 Dec 2006 07:09:29 -0800, "kkmigas@gmail.com" <kkmigas@gmail.com>
wrote:

>Any calculator is able to return the same value has the above.
>
>The so special calc that i am making is quite simple.
>
>200.45 is the price
>1 = quantity
>10 is the discount
>
>((200.45 * 1) * (10/100))
>Price * Qt. * (Discount/100)
>
>I am trying to get how much is the Discount in Price * Qt.
>
>200.45 * 10% gives very simple result ( 200.45 * 0.10 ) = 20.045


If you need 100% accuracy don't use floating point. You should be able
to figure out a way to do what you want with integers, integer division,
mod (modulo), etc.

--

Dennis K.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-28-2008, 08:49 AM
kkmigas@gmail.com
 
Posts: n/a
Default Re: Math BUG??

So your saying that theres no way to "fix" this "problem" you have to
look at the values and get make the necessary changes.

But shouldn't mysql server 4 "fix" the "problem" like in supposedly in
other systems like Mysql 5 and Oracle.

I've tested some values in oracle and all so excel and i allways get

On Dec 26, 3:58 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> kkmi...@gmail.com wrote:
> > On Dec 26, 2:22 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:

>
> >>kkmi...@gmail.com wrote:

>
> >>>It must be something with the libs im using on the background can any
> >>>one tell me witch ones do i need to change or point me to some website
> >>>that explains / solves this problem.

>
> >>>On Dec 26, 11:32 am, "kkmi...@gmail.com" <kkmi...@gmail.com> wrote:

>
> >>>>Using the command with version heres the outputs
> >>>>SELECT VERSION( ) , (( 200.45 *1 ) * ( 10 /100 )), ROUND( ( 200.45 *1 *
> >>>>( 10 /100 ) ) , 2 ) , ROUND( 20.045, 2 ) ;

>
> >>>>Windows 2003
> >>>>5.0.22-community-nt 20.045000 20.05 20.05

>
> >>>>Windows 2003
> >>>>4.1.18-nt-max 20.05 20.05 20.05

>
> >>>>Centos
> >>>>4.1.21-standard 20.04 20.04 20.05

>
> >>>>FreeBSD
> >>>>3.23.58 20.05 20.05 20.05

>
> >>>>After all my testing i've found that the only system that does the
> >>>>Round and the math good is windows.

>
> >>>>On Dec 22, 6:03 pm, Brian Wakem <n...@email.com> wrote:

>
> >>>>>Lee Peedin wrote:

>
> >>>>>>On 21 Dec 2006 07:03:22 -0800, "kkmi...@gmail.com" <kkmi...@gmail.com>
> >>>>>>wrote:

>
> >>>>>>>Can some one plz explain this???

>
> >>>>>>>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2);

>
> >>>>>>>Linux (Servidor Mysql 4)

>
> >>>>>>>20.04 | 20.04

>
> >>>>>>>Windows (Servidor Mysql 4)

>
> >>>>>>>20.05 | 20.05

>
> >>>>>>>Thanks

>
> >>>>>>Here's my results of:
> >>>>>>SELECT VERSION();
> >>>>>>SELECT ((200.45 * 1) * (10/100)),ROUND( (200.45 * 1 * (10/100)) ,2)

>
> >>>>>>Linux
> >>>>>>5.0.24a
> >>>>>>20.45000 | 20.05

>
> >>>>>>Windows
> >>>>>>5.0.24-community-nt
> >>>>>>20.45000 | 20.05Linux 4.1.16

>
> >>>>>20.04 | 20.04

>
> >>>>>Linux 5.0.24-standard-log
> >>>>>20.045000 | 20.05

>
> >>>>>--
> >>>>>Brian Wakem
> >>>>>Email:http://homepage.ntlworld.com/b.wakem/myemail.pngIt'snot a a "problem" - it's how floating point numbers are stored, and

>
> >>the results for your operation will always be somewhat unpredictable.
> >>That's true not only in SQL - but in any language which uses floating
> >>point numbers.

>
> >>The reason this happens is that 20.045 is not exactly 20.045. If you
> >>print it out to enough decimal places, it will come out to something
> >>like 20.04499999967. Rounding this value would (correctly) give a
> >>result of 20.04.

>
> >>The same thing happens in decimal if you try adding 1/3 3 times. You
> >>get .9999999... instead of 1 because 1/3 cannot be expressed directly in
> >>decimal form.

>
> >>The way to resolve it is to add a small value (smaller than the rounding
> >>error) to the number. In your case a value of .001 should suffice
> >>(since you're rounding to 2 decimal places).

>
> >>--
> >>==================
> >>Remove the "x" from my email address
> >>Jerry Stuckle
> >>JDS Computer Training Corp.
> >>jstuck...@attglobal.net
> >>================== > Any calculator is able to return the same value has the above.

> >
> > The so special calc that i am making is quite simple.
> >
> > 200.45 is the price
> > 1 = quantity
> > 10 is the discount
> >
> > ((200.45 * 1) * (10/100))
> > Price * Qt. * (Discount/100)
> >
> > I am trying to get how much is the Discount in Price * Qt.
> >
> > 200.45 * 10% gives very simple result ( 200.45 * 0.10 ) = 20.045
> >
> > the only Mysql Servers that returns the right value are
> > 5.0.22-community-nt 20.045000 20.05 20.05
> > 5.0.22-standard 20.045000 20.05 20.05
> >
> > After all my tests it seems that i am going to mysql 5 sooner than
> > expected since it does all the math correctly.
> >
> > Thanks for all the help. Hope this can also helps someone else.
> > Best Regards
> > Luis Miguel Freitas
> >

>
> (Top posting fixed)
>
> "Any calculator" is not the same as a computer. This problem has
> existed since the dawn of computing - I first saw it when I started with
> Fortran in 1967. That's why there are DECIMAL data types - the data is
> internally stored in a different format, which does have exact decimal
> values.
>
> But floating point values all suffer this problem - in all computers,
> big and small.
>
> And yes, you might have seen a version of MySQL 5.0 which "solves" this
> problem - but it is not a "guaranteed" fix, because it's not a
> "problem". ANY time you round as closely as you are doing, the results
> will be indeterminate. The same is true with truncating;
>
> 0.2 * 5 does not necessarily equal 1.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:44 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335