-2

We have a numeric text field in an html form. For example sales 1500000 We wish to add number formatting(add ',' after every 3 digits),right after the user finishing editing that field so it will show as 1,500,000. Is there a simple way to it in jquery without affecting the field data (just change it in the display of this field)? Thanks

AJ222
  • 1,114
  • 2
  • 18
  • 40

1 Answers1

0

Format numbers in javascript May be it will be helpful Or You may try :

function FormatNumber(val){
    if(val == "" || val == null){
        return "0.00";
    }
    var result = RemoveComma(val).toFixed(2); 
    return result.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

function RemoveComma(val){
    var result = Number(String(val).replace(/,/g, ""));
    return result;
}
Community
  • 1
  • 1
M.Topa
  • 64
  • 1
  • 10