Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Rounding system Algorithm
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00343240
Message ID:
00343496
Views:
21
Hi Bernard,

Try This Function. Can Convert To Class Too..

Function Round
PARAMETERS pnAmount

pnAmount=ROUND(pnAmount,2)
LOCAL lnFraction,lnInteger, lnDecimal

IF ( pnAmount - INT(pnAmount) ) =0
RETU(pnAmount)
ENDIF

lnNearest= alltrim(str(pnamount,20,2))
lnDecimal = AT(".",lnNearest)
lnNearest= STR(pnAmount,lnDecimal+2,2)
lnSecondPositionAfterDecimalPoint=INT(VAL(SUBSTR(ALLT(lnNearest),AT(".",ALLT(lnNearest))+2,1)))

IF lnSecondPositionAfterDecimalPoint=5
RETU(pnAmount)
ENDIF

IF lnSecondPositionAfterDecimalPoint > 5
IF lnSecondPositionAfterDecimalPoint > 7
lnFraction=.10 - (lnSecondPositionAfterDecimalPoint*.01)
lnRoundedAmount=(pnAmount - INT(pnAmount))+lnFraction
ELSE
lnFraction=(lnSecondPositionAfterDecimalPoint*.01)-.05
lnRoundedAmount=(pnAmount - INT(pnAmount))-lnFraction
ENDIF
ELSE
IF lnSecondPositionAfterDecimalPoint > 3
lnFraction=.05 - (lnSecondPositionAfterDecimalPoint*.01)
lnRoundedAmount=(pnAmount - INT(pnAmount))+lnFraction
ELSE
lnFraction=(lnSecondPositionAfterDecimalPoint*.01)-.00
lnRoundedAmount=(pnAmount - INT(pnAmount))-lnFraction
ENDIF
ENDIF

RETU(INT(pnAmount)+lnRoundedAmount)

Regards.
Fred Besterwitch, MCP

The harder you work. The luckier you get.
Previous
Reply
Map
View

Click here to load this message in the networking platform