Rounding Problems
Keywords: Rounding Problems floor int
Question:
Okay! It's time for me to stop beating my head against this wall. I am working with two fields here: Total Premium & Down Payment.I need to round the Down Payment field and take the cents from the Total Premium field and add it to the Down Payment field. (That's the customers formula).
I am having problems rounding the Down Payment and getting it to hold when I convert back to two decimal places. Here is my code:
;totprem is Total Premium ;downpay is Down Payment totprem=2197.93 downpay=702.98 ;first step trim totprem to whole dollar amt totlen=StrLen(totprem) trimlen=totlen-2 suba=StrSub(totprem,trimlen,3) adj-StrCat("0",suba) totprem=totprem-adj ;that worked fine Decimals(0) dp=downpay ;it rounds back down ;need to hold this rounded figure. Decimals(2) downpay=dp+adj ;here it rounds back upAnybody got a magic bullet?Answer:
;totprem is Total Premium
;downpay is Down Payment
totprem=2197.93
downpay=702.98
;first step trim totprem to whole dollar amt
totpremdollars=Floor(totprem)+0.0
totpremcents=totprem-totpremdollars
dp=Int(downpay)+0.0
downpay=dp+totpremcents
3) However Winbatch uses flaoting point math, which is *very close to* but *not the same as* what I'll call currency math.
4) For real dollars and cents math.....maybe (read maybe) use the Hugemath extender. It
does work with "currency math".