使用JavaScript添加两个小数位 [英] Adding Two Decimal Places using JavaScript

查看:78
本文介绍了使用JavaScript添加两个小数位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我想知道如何返回两位小数的输出.我希望它返回10,000.00,而不是10,000.另外,我已经放了.toFixed(2),但是它不起作用.

当金额的十进制数字不是零时,值将显示在打印输出上,但是当十进制数字为零值时,零值将不会显示在打印输出上.

此外,我添加了Wtax的值,该值在账单信用"交易中被拉出.

输出:

解决方案

Numeral.js -是您所使用的库可以用于数字格式. 这样,您可以按照以下格式设置电话号码:

numeral(10000).format('$0,0.00');

希望这会对您有所帮助.

Good day Everyone!

I want to know how to return the output with two decimal places. Instead of 10,000 I want it to return 10,000.00. Also I already put .toFixed(2) but it's not working.

When the amount has decimal number other than zero, the values appear on the printout, but when the decimal number has a zero value, the Zeros won't appear on the printout.

Also, I have added a value of Wtax that was pulled-out on a "Bill Credit" Transaction.

Output:

解决方案

Numeral.js - is a library that you can use for number formatting. With that you can format your number as follows:

numeral(10000).format('$0,0.00');

Hope this will help you.

这篇关于使用JavaScript添加两个小数位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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