Help NaN Error!!!

1. Member
Join Date
Dec 1969
Posts
95

Help NaN Error!!!

The code below only works with currency amounts less than \$999.99. Once a thousand seperator "," (ie: \$1,000)is introduced a "NaN" appears in the field destination.<BR>Any Help?<BR><BR><BR>function cent(amount) {<BR> // returns the amount in the .99 format<BR> return (amount == Math.floor(amount)) ? amount + &#039;.00&#039; : ( (amount*10 == Math.floor(amount*10)) ? amount + &#039;0&#039; : amount);<BR>}<BR><BR> function update(form) {<BR> var subtotal = (form.CommTotal.value - 0) + (form.VendorCost.value - 0) +(form.VendorRushFee.value -0) +(form.VendorSetup.value -0);<BR> subtotal = Math.floor(subtotal * 100)/100;<BR> form.TotalCost.value = cent(subtotal);<BR> form.GrossProfit.value = cent(form.price.value - subtotal);<BR> <BR>}

2. God
Senior Member
Join Date
Dec 1969
Posts
18,177

.

3. Member
Join Date
Dec 1969
Posts
95

RE: Help NaN Error!!!

thanks for replying:<BR><BR>the following form fields return the "Nan" anytime the currency amount is larger than 999.99. Once the thousand seperator comes into play the two form fields return Nan. <BR><BR>form.TotalCost.value = cent(subtotal); <BR> form.GrossProfit.value = cent(form.price.value - subtotal); <BR>

4. Senior Member
Join Date
Dec 1969
Posts
16,931

RE: Help NaN Error!!!

You&#039;ve identified the problem, what&#039;s stopping you just from removing the "," when you do your calculations?<BR><BR>Google for information on the String.replace() method.<BR><BR>Craig.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•