0

I want to show total value of price like this, using Indian numbering system.

1000 = 1K 
1500 = 1.5K 
100000 = 1 LAC

$(document).ready(function() {
  $("#numbr").on("input keydown keyup", function() {
    var val = $('#numbr').val();
    if (val >= 10000000) 
      val = (val / 10000000).toFixed(2) + ' Crore';
    else if (val >= 100000) 
      val = (val / 100000).toFixed(2) + ' Lakh';
    else if (val >= 1000) 
      val = (val / 1000).toFixed(2) + ' Thousand';
      
    $('#show').val(val);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="numbr" type="text" />
<div id="show"></div>
James Z
  • 12,209
  • 10
  • 24
  • 44
  • Possibly you are looking for something like https://stackoverflow.com/questions/10599933/convert-long-number-into-abbreviated-string-in-javascript-with-a-special-shortn – Sonu Bamniya Mar 17 '20 at 12:59
  • `val()` needs to be `text()`. Using `parseFloat()` to prevent type coercion wouldn't hurt either. – Rory McCrossan Mar 17 '20 at 13:02
  • Does this answer your question? [Format number to abbreviated number](https://stackoverflow.com/questions/21521114/format-number-to-abbreviated-number) – Rousonur Jaman Mar 17 '20 at 14:55

1 Answers1

-1

$(document).ready(function() {
  $("#numbr").on("input keydown keyup", function() {

    var val = $('#numbr').val();
    if (val >= 10000000)
      val = (val / 10000000).toFixed(2) + ' Crore';
    else if (val >= 100000)
      val = (val / 100000).toFixed(2) + ' Lakh';
    else if (val >= 1000)
      val = (val / 1000).toFixed(2) + ' Thousand';

    $('#show').html(val);

  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Enter:<br>
<input id="numbr" type="text" />
<br>Result:<br>
<div id="show"></div>
halfer
  • 19,824
  • 17
  • 99
  • 186
vadivel a
  • 1,754
  • 1
  • 8
  • 18
  • Downvoted for "hope this helps". I raised this with you yesterday; it is not technical writing. – halfer Mar 17 '20 at 14:29