How to Use UDF() to Modify Default Scientific Notation FormatID: Q148784 2.00 2.5x 2.60 2.60a | 2.5x 2.60 2.60a 3.00 3.00b | 2.5x 2.60a | 2.60
The information in this article applies to:
SUMMARYThe default formatting that Visual FoxPro applies to numbers requiring scientific notation does not conform to a standard that many customers expect. You can use the user-defined function (UDF) in this article to address this issue.
MORE INFORMATIONThe following program is a UDF() that can process a numeric value into the standard format expected by many customers who have expressed a need for an alternative format for scientific notation:
* Arguments: nExpression is the numeric value to convert to the alternative
* Important notes about minimum and maximum ranges FoxPro will address:
* -------------------------------------------------------------------------
* SET DECIMALS makes no difference to any of this functionality.
* FoxPro will round values beginning at the fifteenth decimal place.
* Margin of error at 15 decimals or more is 3.410910030699E-15.
* The maximums for the STR() function are: STR(n,25,18).
*
* Any value of n.nE+19 or greater will resolve to scientific notation.
*
* Ex: ALLTRIM(STR(1.234567890e+18,25,18))
* Ex: ALLTRIM(STR(1.234567890e+19,25,18))
* Any value passed with n.nE-16 or lower will resolve to equal zero.
*
* Ex: ALLTRIM(STR(1.234567890e-15,25,18))
* Ex: ALLTRIM(STR(1.234567890e-16,25,18))
* These are limitations in FoxPro that cannot be changed. This procedure,
* and therefore any data it processes, is limited to working within these
* constraints.
*
* -------------------------------------------------------------------------
* Stage 1: Convert to character cConvStage1 = UPPER(ALLTRIM(STR(nPassedVal,25,18))) * Find initial location of decimal point nDecimalLoc = ATC(".", cConvStage1) * Find 'E' beginning notation decimals
ELSE
* Stage 2: Value deconstruction and element reformatting
* Swap positions of first two characters
ENDIF
RETURN cRetVal
To convert the value back to numeric, use the VAL() function against the character data NUM2SCI() returned. Additional reference words: 2.00 2.50 2.60 2.60a 3.00 3.00b FoxWin FoxMac FoxUnix FoxDos VFoxWin KBCategory: kbhowto KBSubcategory: FxprgGeneral
|
Last Reviewed: May 22, 1998 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |