javascript - how to get western number pattern (seperated with commas) -


my value coming in input 3440.00, need show 3,440.00

more example: 10,05,000.00 should 1,005,000.00

i got data spring mvc thymeleaf

 <input type="text" class="form-control inputdata"  id="abcd"  th:value="${selecteddetails.abcd}" readonly="readonly"/> 

js is:

  $(document).ready(function() {   var a=$("#abcd").val();  console.log(a);   function *format(a)* {   console.log(acquisitioncost);     return a.tolocalestring("en", {  usegrouping: true,}); } 

i hope problem in javascript. how call method format?

help please.

please check below snippet.

function format1(n) {    n = parsefloat(n);    return n.tofixed(2).replace(/./g, function(c, i, a) {      return > 0 && c !== "." && (a.length - i) % 3 === 0 ? "," + c : c;    });  }  $(document).ready(function(){    var = $("#abcd").val();    console.log(format1(a));  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <input type="text" class="form-control inputdata"  id="abcd"  value="12345.67" readonly="readonly"/>

update

//textfield value var = $("#abcd").val(); //number format value var formatted_a = format1(a); 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -