Michael Collins wrote: > Using MySQL 3.23.47, is the best data type for small currency float(4) ? > This is for prices of items in a shopping cart for example t-shirts. > > What is the difference in using float vs decimal? I know I don't need > double.
Float has accuracy problems at large ranges. A typical float has a fixed number of so-called "significant digits". For 32-bit IEEE floats, that's about 6. Which means that the moment you cross $10000 or so, you lose accuracy in the last place (the cents). The bigger the number, the more the inaccuracy. The *best* type is (depending on the largest quantity you want to deal with) either INTEGER or BIGINT. BIGINT is best. You want to represent either the "cents" value, or preferably, the "centi-cents" value if you want to keep your accuracy to 0.01 cents (i.e. you'd represent $130.31 as 1303100). This allows you to control the rounding exactly, and preserve all significant places in the data (important for currency!). It's a teeny bit more work, but is easily abstracted with a simple high-level data type. -- Shankar. --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php