Currency - toFixed not working

Kale

New Member
I have an order form with 3 fields: Price, Qty and Order CostHere is the exact code for each field:Price:\[code\]<td class="result" align="center"> $<INPUT type="text" maxLength="9" style="text-align:right; width:55px;" align="right" size ="6" id="P<%=i %>" name="P_<%=i%>" value="http://stackoverflow.com/questions/13766083/<%=formatnumber(rstBevInventory("avg_unit_cost"),2)%>"> </td>\[/code\]Qty:\[code\]<td class="result" align="center"><INPUT type="text" maxLength="9" size =6" onChange="reCalcOrder(<%=i %>);" id="Q<%=i%>" name="Q<%=rstDistSQL("supplier") %>_<%=i%>" value="http://stackoverflow.com/questions/13766083/<%=proposed%>">\[/code\]Order Cost:\[code\]<td class="result" align="right">$<Input type="text" maxLength="9" style="text-align:right; width:55px;" align="right" id="OC<%=i %>" value="http://stackoverflow.com/questions/13766083/<%=formatnumber(rstBevInventory("avg_unit_cost"),2)*proposed %>"/></td>\[/code\]As you can see, I have an onChange set so that when I change the Quantity, it recalculates the order cost. Here is that function:\[code\]function reCalcOrder(i){ document.getElementById("OC"+i).value = http://stackoverflow.com/questions/13766083/document.getElementById("P"+i).value * document.getElementById("Q"+i).value; cost = document.getElementById("OC"+i).value; Math.round(cost * 100) / 100; formatCurrency(cost); document.getElementById("OC"+i).value = http://stackoverflow.com/questions/13766083/cost; if (document.getElementById("Q"+i).value < 0){ document.getElementById("Q"+i).value = http://stackoverflow.com/questions/13766083/0; }}\[/code\]The formatCurrency function I added because the round function wasn't working. I also tried this without the round function, but that didn't work either. Here's the formatCurrency function:\[code\]function formatCurrency(num) { num = isNaN(num) || num === '' || num === null ? 0.00 : num; num = num + '0'; return parseFloat(num).toFixed(2);}\[/code\]I have tried this and using toFixed(2) to get the currency in the Order Cost field to display properly, but it doesn't work. For example, right now if I put in a Qty of 6 with a price of 6.36, the result comes out 38.160000000000004. Even when I use toFixed, it has all those extra digits after the decimal.Am I missing something?EDIT: It seems like it changes the value shown in the text box, but not the value attribute for the input. Maybe this has something to do with it?
 
Back
Top