0

Here's the code

<script type="text/javascript">


 $(document).ready(function(){

$('input.number')

  .on("blur", function(e){
    var $this = $(this);
    var num = $this.val().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");     

    $this.val(num);
});

});

  </script>

The output of that code is 10000 => 10,000

I want the output to be 10000 => 10,000.00

thanks..

seven
  • 115
  • 1
  • 1
  • 9
  • var num = parseFloat($this.val()).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); – seven Aug 17 '15 at 08:51

2 Answers2

2

You could also make use of toLocaleString with minimumFractionDigits property of its options argument.

numObj.toLocaleString([locales [, options]])

Example:

var number = 10000;
alert(number.toLocaleString('en-US', { minimumFractionDigits: 2 }));

Note: Supported by all modern browsers, except Safari (it seems)

Abhitalks
  • 27,721
  • 5
  • 58
  • 81
1

Use this:

parseFloat(num).toFixed(2)

Like:

$this.val(parseFloat(num).toFixed(2));//output 1000.00

For comma separator use this SO ANSWER.

function commaSeparateNumber(val){
    while (/(\d+)(\d{3})/.test(val.toString())){
      val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
    }
    return val;
  }
var num = 10000;
console.log(commaSeparateNumber(parseFloat(num).toFixed(2)));// output 10,000.00

DEMO

Community
  • 1
  • 1
Manwal
  • 23,450
  • 12
  • 63
  • 93