DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 51414 - Last Review: August 23, 2013 - Revision: 2.1

 
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 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
				

APPLIES TO
  • 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
Keywords: 
kbnosurvey kbarchive KB51414
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support