[英]how to add two methods together in javascript
I have this following method:我有以下方法:
document.formcalc.txtres.value = new Intl.NumberFormat('de-CH', { style: 'currency', currency: 'CHF' }).format(num2);
But I also want to add the round method: Math.round(num2);
但我也想添加round方法: Math.round(num2);
Can someone explain me how to add this two methods together?有人可以解释我如何将这两种方法添加在一起吗?
只需将 num 2 提供给Math.round
并将其整个放入format()
document.formcalc.txtres.value = new Intl.NumberFormat('de-CH', { style: 'currency', currency: 'CHF' }).format(Math.round(num2));
This should be what you are looking for;这应该是你正在寻找的; if it's not, I added a second statement that you can try aswell.如果不是,我添加了第二个语句,您也可以尝试。
document.formcalc.txtres.value = new Intl.NumberFormat('de-CH', { style: 'currency', currency: 'CHF' }).format(Math.round(num2));
And the other solution:另一个解决方案:
document.formcalc.txtres.value = Math.round(new Intl.NumberFormat('de-CH', { style: 'currency', currency: 'CHF' }).format(num2));
For the newbies out there, The answer by ellipsis worked great but what you're looking at can be found here http://www-lia.deis.unibo.it/materiale/JS/developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat.html#:~:text=Intl.NumberFormat%201%20Summary.%20The%20Intl.NumberFormat%20object%20is%20a,A%20reference%20to%20Intl.NumberFormat.%20...%205%20Examples.%20对于那里的新手,省略号的答案效果很好,但您可以在此处找到您正在查看的内容http://www-lia.deis.unibo.it/materiale/JS/developer.mozilla.org/en-US /docs/Web/JavaScript/Reference/Global_Objects/NumberFormat.html#:~:text=Intl.NumberFormat%201%20Summary.%20The%20Intl.NumberFormat%20object%20is%20a,A%20reference%20to%20Intl.NumberFormat .%20...%205%20 示例。%20
In my case, I needed to take away the locale, 'de-CH'.就我而言,我需要去掉语言环境“de-CH”。 Currency worked well for me as the style and I changed the currency to USD.货币作为风格对我来说效果很好,我将货币更改为美元。
var num2=(12/5);
document.formcalc.txtres.value= new Intl.NumberFormat({ style: 'currency', currency: 'USD' }).format(Math.round(num2));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.