javascript - 使用印度编号系统显示价格
问题描述
我想使用印度编号系统显示这样的价格总价值。
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>
解决方案
$(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>
推荐阅读
- javascript - 将文件的base64值发送到api
- regex - RegEx中的具体位置
- javascript - Promises/A+ 规范和 ECMAScript 承诺之间可能存在矛盾?
- apache - 无法使用 logstash grok 解析 apache access.log
- python - 按钮无论如何都占据全屏
- typescript - 如何在测试中使用在 beforeAll() 钩子中分配了值的变量
- node.js - Mongoose 和 TypeScript - 返回的 _id 格式奇怪
- azure - 使用 azure cli 自动为资源创建诊断设置
- javascript - 我在基于字符串参数改变堆栈时收到了这个面试问题的问题
- node.js - 流星/节点测量重定向或处理生成的日志