首页 > 解决方案 > 使用印度编号系统显示价格

问题描述

我想使用印度编号系统显示这样的价格总价值。

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>

标签: javascriptjquery

解决方案


$(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>


推荐阅读