Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need a function to strip off zero-filled decimals
Message
From
18/08/2000 13:49:09
 
 
To
18/08/2000 12:44:31
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00406732
Message ID:
00406756
Views:
30
>I must be suffering from temporary brainlock, but I need a function that will remove the zeros from the decimal portion of a number, without changing the SET("DECIMALS") setting.
>
>Example: I have a variable that contains the number 8.50000. I want to pass that through a VFP function and have it return 8.5. Passing 8.50001 will return 8.50001, regardless of what my SET("DECIMALS") setting is.
>

Try this, e.g.
LPARAMETERS tnNum, tlRetNum
LOCAL lcNum, lnDecs
lcNum = LTRIM(STR(tnNum,40,14))
DO WHILE RIGHT(lcNum,1)="0" OR RIGHT(lcNum,1)="."
  lcNum = LEFT(lcNum,LEN(lcNum)-1)
ENDDO
IF !tlRetNum
  RETURN lcNum
ELSE
  lnDecs = IIF("." $ lcNum, LEN(SUBSTR(lcNum, AT(".",lcNum)+1)), 0)
  RETURN ROUND(VAL(lcNum),lnDecs)
ENDIF
>While I'm at it, is there a function that will tell you the number of decimals in a numeric?
>
>Example 2: I have a variable that contains the number 12.345. Passing it through the decumal counter function will return 3. Passing 99.5000 will return 4, and passing 144 will return 0, again without querying or changing the SET("DECIMALS") setting.
>

See the "lnDecs = ..." line above.

>TIA,
>
>Bill

HTH
Insanity: Doing the same thing over and over and expecting different results.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform