Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,
I want to display numbers as comma separated string
(like we show amount 12,34,675.67)

I have a javascript function, which I call on onkeyup event of a textbox.
Here is that function :
JavaScript
function Comma(Num) 
{
     Num += '';
     Num = Num.replace(/,/g, '');

      x = Num.split('.');
      x1 = x[0];
      x2 = x.length > 1 ? '.' + x[1] : '';
      var rgx = /(\d+)(\d{3})/;
      while (rgx.test(x1))
         x1 = x1.replace(rgx, '$1' + ',' + '$2');
      
      return x1 + x2;
} 

This function gives me the amount as
123,456,984.00

Now, if I repoen my Voucher, I have formatted the textbox for amount using
C#
.ToString("N")

which shows me the value as
12,34,67,567.00

AS you can see, there is difference in comma placings of these two functions.

How can I achieve the same format for amount ??
And it will be a lot better, if the value is rounded by two digits after decimal point.

Any help is appreciated.

Thanks,
Lok..
Posted

 
Share this answer
 
v4
Comments
Uday P.Singh 5-Dec-11 12:59pm    
5ed :), but the link is not available
Wonde Tadesse 5-Dec-11 13:00pm    
Thanks
Uday P.Singh 5-Dec-11 13:03pm    
I added a new link.
Wonde Tadesse 5-Dec-11 13:06pm    
Opps :( I updated the link.
Lokesh Zende 6-Dec-11 0:04am    
Thanks for the replies..
But my client is not happy with the behaviour of MaskedEditExtender.
It shows commas and dot while typing, which he thinks is quit annoynig.

Could you please help me with what I have (i.e. that script function) ???
Why not use one of the many existing Masked Edit controls?
 
Share this answer
 
Comments
Uday P.Singh 5-Dec-11 13:00pm    
5ed :)

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