double vs. float

This is a discussion on double vs. float within the MySQL Database forums, part of the Database Forums category; I've inherited a mysql (5.x) table that stores amounts as a double in a column. If I sum(...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-17-2008
Steve
 
Posts: n/a
Default double vs. float

I've inherited a mysql (5.x) table that stores amounts as a double in
a column.

If I sum(tbl_ra_amount) as amt for a particular user, I can get a 2
decimal number: 521.93

Now if I want to zero that account out, I insert another transaction
using the negative of the sum: -521.93, but I'm getting some huge
decimal remainders: 1.13686837722.

I've tried an experiment where I first updated the values for this
user using update... set tbl_ra_amount = round(tbl_ra_amount,2) where
user etc. - but that's not giving me a nice 2 decimal amount to
subtract.

Is there a way to either truly convert all of the amounts to rounded 2
decimal amounts (which is fine - we don't need more precision than
that), or, figure out what the true amount to subtract would be to
give me a 0 "balance"?

Reply With Quote
  #2 (permalink)  
Old 01-17-2008
Peter H. Coffin
 
Posts: n/a
Default Re: double vs. float

On Thu, 17 Jan 2008 06:47:34 -0800 (PST), Steve wrote:
> I've inherited a mysql (5.x) table that stores amounts as a double in
> a column.
>
> If I sum(tbl_ra_amount) as amt for a particular user, I can get a 2
> decimal number: 521.93
>
> Now if I want to zero that account out, I insert another transaction
> using the negative of the sum: -521.93, but I'm getting some huge
> decimal remainders: 1.13686837722.
>
> I've tried an experiment where I first updated the values for this
> user using update... set tbl_ra_amount = round(tbl_ra_amount,2) where
> user etc. - but that's not giving me a nice 2 decimal amount to
> subtract.
>
> Is there a way to either truly convert all of the amounts to rounded 2
> decimal amounts (which is fine - we don't need more precision than
> that), or, figure out what the true amount to subtract would be to
> give me a 0 "balance"?


Sure, put them all in DECIMAL instead of the approximation types like
FLOAT and DOUBLE. See
http://dev.mysql.com/doc/refman/5.0/...ric-types.html

--
Give a man a fish and you feed him for a day; give him a freshly-charged
Electric Eel and chances are he won't bother you for anything ever again.
-- Tanuki
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:54 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0