Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Multiplying?
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Multiplying?

 Post Reply Post Reply
Author
RaeEveMay View Drop Down
New Member
New Member
Avatar

Joined: 31 Jan 2012
Location: Big Bear Lake
Points: 7
Post Options Post Options   Quote RaeEveMay Quote  Post ReplyReply Direct Link To This Post Topic: Multiplying?
    Posted: 31 Jan 2012 at 12:54am
I've tried this with java too but here is the simple calc. example I am having problems with:

(Value is the product (x) of the following fields:
AmtPay1new, Number of Payments

AmtPay1new value=$916.67
Number of Payments=12

I keep getting $11,000.00 instead of $11,000.04 

Any ideas are greatly appreciated. Is this case 4 cents matter (believe it or not).

Thank you,

Rae


Back to Top
Sponsored Links


Back to Top
aandi View Drop Down
Senior Member
Senior Member


Joined: 07 Jul 2011
Points: 18358
Post Options Post Options   Quote aandi Quote  Post ReplyReply Direct Link To This Post Posted: 31 Jan 2012 at 4:04pm
If you're working with money exact accuracy is important, so it's vital to understand exactly how JavaScript stores numbers. Auditors will demand as much! A common approach is to work in cents/pennies, and round up only for display.
Back to Top
RaeEveMay View Drop Down
New Member
New Member
Avatar

Joined: 31 Jan 2012
Location: Big Bear Lake
Points: 7
Post Options Post Options   Quote RaeEveMay Quote  Post ReplyReply Direct Link To This Post Posted: 31 Jan 2012 at 6:51pm
My display actually needs to show the cents too (it's for the disclosure of the total of payments on a loan). I am not putting in any rounding options within the .pdf. Is that something that java does all on it's own? If so, how do I get it to knock it off? 

The fields that have a monetary value are formatted as Number, 2 Decimal Places and a separator style of 1,234.56. 

The Number of payments field is formatted as Number, 0 Decimal Places and a separator style of 1234.56.

I'd break it down into cents, like you suggested, but I don't see how it will hold a value if the java continues to round.

Thanks again for any info.

-Rae
Back to Top
RaeEveMay View Drop Down
New Member
New Member
Avatar

Joined: 31 Jan 2012
Location: Big Bear Lake
Points: 7
Post Options Post Options   Quote RaeEveMay Quote  Post ReplyReply Direct Link To This Post Posted: 31 Jan 2012 at 8:50pm
Yeah! I got it. The problem was it was taking the full value of the  AmtPay1new field ( $916.6666666666665) which does, in fact =$11,000.00 so I needed to round that figure in a new field called AMT_PAY1new2points. Here is the script:

var nValue = this.getField("AMT_PAY1new").value;
var nPrecision = +2;
nPrecsision = -nPrecision;
var nAdjustment = Math.pow(10, nPrecision);
nValue = nValue * nAdjustment;
nValue = Math.ceil(nValue);
event.value = nValue / nAdjustment;

My total of payment (and finance charge accordingly) reads $11,000.04

Back to Top
aandi View Drop Down
Senior Member
Senior Member


Joined: 07 Jul 2011
Points: 18358
Post Options Post Options   Quote aandi Quote  Post ReplyReply Direct Link To This Post Posted: 31 Jan 2012 at 10:34pm
The point about storing dollars and counting cents is that no fractions are stored exactly. They are in floating point, and this can have surprising consequences.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.051 seconds.