Internal Format of CURRENCY Data Type in Basic products

ID: Q51414


The information in this article applies to:
  • Microsoft Visual Basic Standard and Professional Editions for MS-DOS, version 1.0
  • Microsoft Visual Basic for Windows, version 1.0
  • Microsoft QuickBASIC for MS-DOS, versions 4.0, 4.0b, 4.5
  • Microsoft BASIC Professional Development System (PDS) for MS-DOS, versions 7.0, 7.1


SUMMARY

The CURRENCY data type is an 8-byte signed integer scaled by 10,000. This allows a variable of the CURRENCY type to have a range of:


   (2 ^ 63 -1) / 10,000  =  +922337203685477.5807 
To

   (2 ^ 63) / 10,000   =  -922337203685477.5808 
Up to 19 digits are allowed, with no more than 4 digits to the right of the decimal point.


MORE INFORMATION

Because the CURRENCY type is scaled by 10,000, its internal representation is the actual value multiplied by 10,000. For instance, a CURRENCY variable holding the value 0.0001 will be stored as follows:


HIGH BYTE                                                     LOW BYTE
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000001 
As with ordinary INTEGERs, the higher byte is stored at the higher memory address so that once you find the address of the variable, you will find the low byte there, the second byte stored above, the third byte above that, etc. The example program listed below displays the hexadecimal machine representation for a CURRENCY data type variable whose value is INPUT from the keyboard.

Sample Code:

'To try this example in VBDOS.EXE:
' 1. From the File menu, choose New Project.
' 2. Copy the code example to the Code window.
' 3. Press F5 to run the program.
'
'To try this example in VB.EXE:
' 1. From the File menu, choose New Project.
' 2. Copy the code example to Form_Click event procedure.
'    (Note: code will have to be slightly changed for VB)
' 3. Press F5 to run the program.
' 4. Click on the Form
'
'To try this example in QB.EXE or QBX.EXE
' 1. From the File menu, choose New Program.
' 2. Copy the code example to the Code window.
' 3. Press F5 to run the program.
'
'******************************************************************
'     Sample program to display machine representation of the     *
'     CURRENCY data type (8-byte scaled INTEGER)                  *
'******************************************************************
CLS
DO UNTIL INKEY$ = CHR$(27)
  PRINT "Enter a CURRENCY value.  The machine representation will be "
  PRINT "displayed in Hex"
  INPUT a@                   ' "@" is the CURRENCY data type suffix.
  address% = VARPTR(a@)      ' Get the address of the variable a@.

  FOR i% = 7 TO 0 STEP -1
     PRINT HEX$(PEEK(address% + i%)); "  ";  ' Display representation
  NEXT i%                                    ' in normal Low-Byte to
                                             ' the right form.
  PRINT
  PRINT "press a key to continue, Esc to EXIT"
  SLEEP
LOOP 

Additional query words: VBmsdos QuickBas BasicCom 1.00 4.00 4.00b 4.50 7.00 7.10

Keywords :
Version : MS-DOS:1.0,4.0,4.0b,4.5; :1.0,7.0,7.1
Platform : MS-DOS
Issue type :


Last Reviewed: December 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.