Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi..
check the following code..

<script type="text/javascript">
      var indMoney = function (v)
      {
        v = (Math.round((v - 0) * 100)) / 100;
        v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
        v = String(v);
        var ps = v.split('.'),
          whole = ps[0],
          sub = ps[1] ? '.' + ps[1] : '.00',
          r = /(\d+)(\d{3})/;
        while (r.test(whole))
        {
          whole = whole.replace(r, '$1' + ',' + '$2');
        }
        v = whole + sub;

        return v;
      }
</script>


The result of the above function is displaying like this 123,123,123.00
but i want in this format 12,12,12,12,123.00 i.e indian currency format..
Posted
Updated 24-Feb-11 23:42pm
v2
Comments
Richard MacCutchan 25-Feb-11 5:25am    
You already posted this in the Java forum; post in one place only please.

1 solution

try this its working
 function changeNo (v)
{
v = (Math.round((v - 0) * 100)) / 100;
v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
v = String(v);
var ps = v.split('.'),
whole = ps[0],
sub = ps[1] ? '.' + ps[1] : '.00',
r = /(\d+)(\d{2})/;
if(parseInt(whole)>999)
{
var whole1=whole.substring(whole.length-3);
var whole2=whole.substring(0,whole.length-3);
while (r.test(whole2))
{
whole2 = whole2.replace(r, '$1' + ',' + '$2');
}
v = whole2+','+whole1 + sub;
}
else
{
v = whole+ sub;
}
return v;
}
 
Share this answer
 
Comments
vinu.1111 25-Feb-11 5:50am    
thanku sir... it really helped me..
pankajupadhyay29 25-Feb-11 5:53am    
welcome dear.
pankajupadhyay29 25-Feb-11 5:56am    
ok mark this as answer.
--Pankaj
vinu.1111 25-Feb-11 7:27am    
hi...
there's one problem
it is not showing for negative values...
what to do now

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