vbdpss.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Article Q35826, Method 1
                                                 Contents  Index  Back
─────────────────────────────────────────────────────────────────────────────
                           Knowledge Base Contents  Knowledge Base Index
 
 IEEE vs. Microsoft Binary Format; Rounding Issues (Complete) - Q35826
 
    Method 1
    --------
 
    If the range of numbers is between 2^32/100 and -2^32/100, the
    following method can be used:
 
    ' 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.
 
    FUNCTION round2$ (number#)
    n& = number# * 100#
    hold$ = LTRIM$(RTRIM$(STR$(n&)))
 
    IF (MID$(hold$, 1, 1) = "-") THEN
       hold1$ = "-"
       hold$ = MID$(hold$, 2)
    ELSE
       hold1$ = ""
    END IF
 
    length = LEN(hold$)
    SELECT CASE length
    CASE 1
       hold1$ = hold1$ + ".0" + hold$
    CASE 2
       hold1$ = hold1$ + "." + hold$
    CASE ELSE
       hold1$ = hold1$ + LEFT$(hold$, LEN(hold$) - 2)
       hold1$ = hold1$ + "." + RIGHT$(hold$, 2)
    END SELECT
     round2$ = hold1$
    END FUNCTION
 
    The value being rounded is multiplied by 100# and the result is
    stored in a long integer. The long integer is converted to a string
    and the decimal point is inserted in the correct location.