javascript中的货币格式编号 [英] number to currency format in javascript

查看:75
本文介绍了javascript中的货币格式编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数字转换为印度货币格式...它适用于0-9(48-57 ascii值).. bt为0-9(97-105)它会产生问题ny代码是



I want to convert number to indian currency format ...It works perfactly for 0-9(48-57 ascii value)..bt for 0-9(97-105) it creates problem ny code is

$('input.number').keyup(function(event) {

          // skip for arrow keys


      if (event.which >= 31 && event.which <= 48 || event.which > 57 && event.which <= 97 || event.which > 105) return;

          // format number

          $(this).val(function(index, value) {
              return value
                  .replace(/\D/g, '')
                  .replace(/(\d)(?=(\d\d)+\d$)/g, "$1,")
              ;
          });
      });







为48到57它给出了输出== 1,111

bt为97到105它确实在perfact位置附加逗号....我在文本框中发布了这个funnction onkeypress事件..........并且在97到105之间它在一个之后工作退格



....




for 48 to 57 it gives output==1,111
bt for 97 to 105 it does attach comma at perfact place....i caaled this funnction onkeypress event of textbox..........and in 97 to 105 key it works after one backspace

....

推荐答案

' input.number')。keyup(function( event ){

// 跳过箭头键


< span class =code-keyword> if ( event .which > = < span class =code-digit> 31 && event .which < = 48 || 事件 .which > 57 && event .which < = 97 | | event .which > 105 )< span class =code-keyword> return ;

// 格式编号
('input.number').keyup(function(event) { // skip for arrow keys if (event.which >= 31 && event.which <= 48 || event.which > 57 && event.which <= 97 || event.which > 105) return; // format number


this )。val(function(index, value ){
return value
.replace(/ \D / g, ' '
.replace(/(\ d)(?=(\\\)+ \\\
(this).val(function(index, value) { return value .replace(/\D/g, '') .replace(/(\d)(?=(\d\d)+\d


)/ g,
)/g, "


这篇关于javascript中的货币格式编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆