
CDbl and decimal places
Is it possible to return a number with more decimal places than the CDbl(x) function? For example, if I have a variable like pi, and use CDbl(pi), it returns the following:<BR>3.14159265358979<BR><BR>What if I need more than just 14 decimal places? Not that I ever would, I'm just curious.<BR>

RE: CDbl and decimal places
Try FormatNumber(), FormatCurrency(), ...

RE: CDbl and decimal places
formatnumber(pi,30) returned the following:<BR>3.141592653589790000000000000000<BR> <BR>Again, accurate only up to 14 decimal places.<BR><BR>Formatcurrency returns the same number, only with a dollar sign in front of it.

RE: CDbl and decimal places
Yes... that's why I said *Try* as in maybe it could've helped but i guess not!

Understanding numbers...
A DOUBLE uses 8 bytes of memory.<BR><BR>For most computer languagesincluding JS and VBSa double provides you with the greatest range of values. In many languagesagain, including VBS and JSdouble *also* provides the greatest amount of accuracy. <BR><BR>This is primarily because double is one of the data types implemented *IN THE HARDWARE* of most computer chips (and that has been true since the days of the first IBM 360'sabout 1966 or so). And, again, it typically has the largest range and accuracy of all the hardware types. [That's slowly changing, but you can expect it to take another 5 years or so to trickle down to a desktop machine.]<BR><BR>The other data types that are done in hardware in a PC are SINGLE (4 byte floating point), LONG (4 byte integers), INT (2 byte integers), byte (not used in VBS or JS), and bit (ditto).<BR><BR>These are often referred to as the "primitive" types. Meaning there are "primitives" in the machine instruction set that can operate on them.<BR><BR>Here's a summary of the types as they are available from VBS:<BR>http://msdn.microsoft.com/library/enus/script56/html/vbsDataType.asp<BR><BR>Back to double: In 8 bytes, 11 bits are used just to remember the "exponent" (that is, the power of two, which says where the binary point should be placed) and 53 remember the "mantissa".<BR><BR>In other words, the computer can represent any *INTEGER* of up to 53 bits accurately. Or (using 2^52, since we need a bit for the sign) *roughly* 4,503,599,625,000,000. That's 15 digits (plus 0 to 4 in the 16th digit, but since we can't count on the <BR>value in that first digit, we ignore it).<BR><BR>The "exponent" field is then used to multiply or divide that by by powers of two, but that doesn't change the basic limitation that you can't get more than 15 decimal digits of integer accuracy out of 53 bits.<BR><BR>And the routine in VBS (and JS) that converts an internal format number to humanreadable form is aware of this limitation and so never tries to produce more than 15 digits, decimal, from that internal binary format.<BR><BR>So...Yep, you can only "see" 14 digits to the right of the decimal point when you have one digit to the left of it. If you had 7 digits to the left of the decimal point, you'd only "see" 8 digits to the right. Etc. 15 digits total.<BR><BR>
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

