javascript - How to allow comma to my addition codes -


these code working; adding correctly. problem if want add 99000000.00 + 199000000.00 displays 298000000.00.

how can make 99,000,000.00 + 199,000,000.00 displays 298,000,000.00?

every time compute numbers comma, results nan/invalid. if compute numbers without comma, computes well. how allow comma in text area/numbers inputted users without having nan/invalid result?

please see code used below:

html code:

<table width="460" border="1">                    <tr>                         <tr>                         <td>south cluster (391)</td>                         <td><input name="scc" type="text" size="25" id="scc" value="0.00"/></div></td>                         </tr>                         <tr>                         <td>central cluster(387)</td>                         <td><input name="ccc" type="text" size="25" id="ccc" value="0.00" /></div></td>                         </tr>                         <tr>                         <td>north cluster(393)</td>                         <td><input name="ncc" type="text" size="25" id="ncc" value="0.00"  /></div></td>                         </tr>                         <tr>                         <td >c hub(390)</td>                         <td><input name="vch" type="text" size="25" id="vch" value="0.00"/></div></td>                         </tr>                         <tr>                         <td>ch hub(397)</td>                         <td><input name="mch" type="text" size="25" id="mch" value="0.00"/></div></td>                         </tr>                         <tr>                         <td>nlc hub(399)</td>                         <td><input name="nlch" type="text" size="25" id="nlch" value="0.00"/></div></td>                         </tr>                         <tr>                         <td>slc hub(396)</td>                         <td><input name="slch" type="text" size="25" id="slch" value="0.00"/></div></td>                         </tr>                         <tr>                         <td>&nbsp;</td>                         <td>&nbsp;</td>                         </tr>                         <tr>                         <td>                         <td><div class="style66" align="center"><input type="button" value="add" onclick="civ()"></center></td>                         </tr> 

javascript codes:

function civ(){ civ1=number(document.addition.scc.value); civ2=number(document.addition.ccc.value); civ3=number(document.addition.ncc.value); civ4=number(document.addition.vch.value); civ5=number(document.addition.mch.value); civ6=number(document.addition.nlch.value); civ7=number(document.addition.slch.value); valnum1=math.floor((civ1+civ2+civ3+civ4+civ5+civ6+civ7)*100)/100; document.addition.civ123.value=valnum1; } 

when have commas, not number (nan).

a quickfix add in function convert them number

function numwithcomma(num){     return parseint(num.replace(",","")); } 

then do

civ1 = numwithcomma(document.addition.scc.value); 

this quickfix, in opinion there many things wrong have posted...hopefully helps somehow


Comments