Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am doing client side calculation in my application. Everything was working fine until client asked for number formatting. i.e

first it was 1000 + 2000 = 3000

this works fine but client's demand was 1,000 instead of 1000. I succeeded format the number using some Jquery plugins. But now I dont get calculations. Instead I get NaN in a result textbox.

Any help about this issue??

JavaScript
function GetTotal(val1,val2)
{
    documennt.getElementById('<%=txtResult.ClientID%>').value = Number(val1) + Number(val2);
}
Posted
Updated 12-Mar-12 0:42am
v2
Comments
Bojjaiah 12-Mar-12 6:38am    
can u post your code?
hiren soni 12-Mar-12 6:43am    
i did.
Herman<T>.Instance 12-Mar-12 6:55am    
have you read this?
hiren soni 12-Mar-12 7:35am    
yes but result is still not correct. Using that method 1,000 + 2,000 i got 3 instead of 3,000.

try this

JavaScript
function GetTotal( val1, val2 ) {
           document.getElementById( '<%=txtResult.ClientID%>' ).value = parseInt( val1 ) + parseInt( val2 );
       }
 
Share this answer
 
v2
Comments
hiren soni 12-Mar-12 7:20am    
Tried your code with ParseInt and ParseFloat but it gives result like
1,000 + 2,000 = 3
Bojjaiah 12-Mar-12 8:35am    
remove commas give=1000; like this
and document not documennt
checkout spelling in your code

?..........
try this:

JavaScript
function GetTotal( val1, val2 ) {
           document.getElementById( '<%=txtResult.ClientID%>' ).value = parseInt( val1.replace(',','') ) + parseInt( val2.replace(',','') );
       }
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900