Jim Dettman
jimdettman at verizon.net
Mon Jan 14 06:05:56 CST 2008
Rocky, Currency is a special data type in that it is a scaled integer to four decimal places. What that means is that for up to four decimal places, the number will always be accurate. It achieves this by scaling a number you hand it. For example, when given 1234.5678, it's actually stored as 12345678. It's scaled up by 10^4. When you get the number back, it's scaled down. The reason for this data type is that decimal operations with the Double and single data types are not guaranteed. It has to do with the fundamental differences between binary and decimal arithmetic. Luke Chung has written several papers on this over the years in regards to Microsoft products. Here's one of them: http://www.fmsinc.com/tpapers/math/index.html The Decimal data type was added latter and allows you to specify the scaling factor. However the more you scale, the less significant digits (overall range) you'll have to work with. Jim. -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Rocky Smolin at Beach Access Software Sent: Sunday, January 13, 2008 10:19 PM To: 'Access Developers discussion and problem solving' Subject: Re: [AccessD] Currency vs Double So it sounds like currency has its own rounding problems? I'm trying to avoid the rounding problem in an application and read somewhere that using Currency data type accomplishes this. Rocky -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Sunday, January 13, 2008 7:07 PM To: 'Access Developers discussion and problem solving' Subject: Re: [AccessD] Currency vs Double Rocky, Currency only stores 4 decimal points, double stores "a lot" (don't have the number off the top of my head). A double is really a "floating point" number whereas a currency is specifically used to handle money. Currency needs lots of numbers to the left of the decimal point, but does not need a lot to the right. Currency rounds numbers beyond the 4th decimal place to cause the 4th decimal place to display the rounded effects of the 5th decimal place. 123.45678 becomes 123.4568 123.45674 becomes 123.4567 Basically this results in differences between complex math operations. ?ccur(1/3)*3 0.9999 ?1/3*3 1 ?cdbl(1/3)*3 1 As you can see, because of the larger numbers of decimal points stored, a float ends up with 1 from the previous operation whereas the currency type ends up with .9999. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Rocky Smolin at Beach Access Software Sent: Sunday, January 13, 2008 1:32 PM To: 'Access Developers discussion and problem solving' Subject: [AccessD] Currency vs Double Dear List: Is there any difference between currency and double when working with relatively small number - like under a million? Does currency take care of rounding errors which would happen in double calculations? MTIA Rocky -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.19.2/1223 - Release Date: 1/13/2008 8:23 PM -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com