Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dropping decimals when printing a report
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01123493
Message ID:
01127778
Vues:
16
Sergey,

very elegant. I will keep this in mind. I hadn't noticed that the trim function had changed to this in VFP9. Unfortunately these applications still run in VFP8.
I solved it like this.

PROCEDURE RemoveDecimals (nNumber as number)
* be aware, the number is retured as a string!!!! without trailing zero's
PRIVATE nNewNumber, nCounter, cNewNumber, nSetDecimals
nSetDecimals = SET('Decimals')
nNewNumber = nNumber - INT(nNumber)
cNewNumber = STR(nNumber, 10,3)

* how many decimals does this number have?
cNewNumber = ALLTRIM(STR(nNewNumber,20,10))
FOR nCounter = LEN(cNewNumber) TO 1 STEP -1
IF SUBSTR(cNewNumber,nCounter,1) = SET('POINT') OR SUBSTR(cNewNumber,nCounter,1) <> '0'
EXIT && loop
ENDIF
ENDFOR

IF nCounter > 1
cDecimals = SUBSTR(cNewNumber, 1, nCounter)
* drop the 0. infront of the number
cDecimals = SUBSTR(cDecimals, 3,LEN(cDecimals))
IF LEN(cDecimals) > 0
cNewNumber = ALLTRIM(STR(INT(nNumber),10,0)) + SET('POINT') + cDecimals
ELSE
cNewNumber = ALLTRIM(STR(INT(nNumber),10,0))
ENDIF
ENDIF
SET DECIMALS TO nSetDecimals
RETURN (cNewNumber )



Yours is far more elegant :-)

>>In a report I need to print numbers with only the relevant decimals. 100.001 should print the same but 100.000 should only print as 100. Is there an easy way to do this or do I need to program this?
>
>VFP9 only
>RTRIM(RTRIM(TRANSFORM(1000.000, "999,999.999"), "0"), ".")
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform