Internal Format of CURRENCY Data Type in Basic products

This article was previously published under Q51414
This article has been archived. It is offered "as is" and will no longer be updated.
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 rightof the decimal point.
MORE INFORMATION
Because the CURRENCY type is scaled by 10,000, its internalrepresentation is the actual value multiplied by 10,000. Forinstance, a CURRENCY variable holding the value 0.0001 will be storedas follows:
HIGH BYTE                                                     LOW BYTE00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000001				
As with ordinary INTEGERs, the higher byte is stored at the highermemory address so that once you find the address of the variable, youwill find the low byte there, the second byte stored above, the thirdbyte above that, etc. The example program listed below displays thehexadecimal machine representation for a CURRENCY data type variablewhose 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)                  *'******************************************************************CLSDO 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"  SLEEPLOOP				
VBmsdos QuickBas BasicCom 1.00 4.00 4.00b 4.50 7.00 7.10
Properties

Article ID: 51414 - Last Review: 08/23/2013 17:28:57 - Revision: 2.1

  • Microsoft Visual Basic for MS-DOS
  • Microsoft Visual Basic 1.0 Standard Edition
  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Professional Development System 7.0
  • Microsoft BASIC Professional Development System 7.1
  • kbnosurvey kbarchive KB51414
Feedback