美国货币格式

时间:2019-09-25 16:45:52

标签: javascript

$('#currency').inputmask("numeric", {
  radixPoint: ".",
  groupSeparator: ",",
  digits: 2,
  autoGroup: true,
  prefix: '$ ', //Space after $, this will not truncate the first character.
  rightAlign: false,
  oncleared: function() {
    self.Value('');
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="form-control" id="currency" name="currency">
<script type='text/javascript' src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>

输入= 15097040
输出= $ 15,097,040

应该是这样的:$150,970.40。谁能帮助您正确设置格式?

1 个答案:

答案 0 :(得分:0)

尝试使用:Number.prototype.toFixed

这是类似的情况: How can I format numbers as currency string in JavaScript?