【问题标题】:how to add two methods together in javascript如何在javascript中将两个方法一起添加
【发布时间】:2019-06-28 04:50:21
【问题描述】:

我有以下方法:

document.formcalc.txtres.value = new Intl.NumberFormat('de-CH', { style: 'currency', currency: 'CHF' }).format(num2);

但我也想添加round方法:Math.round(num2);

谁能解释一下如何将这两种方法加在一起?

【问题讨论】:

    标签: javascript jquery html function


    【解决方案1】:

    对于新手来说,省略号的答案效果很好,但您可以在此处找到您正在查看的内容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

    就我而言,我需要删除语言环境“de-CH”。货币作为样式对我来说效果很好,我将货币更改为美元。

    var num2=(12/5);
    document.formcalc.txtres.value= new Intl.NumberFormat({ style: 'currency', currency: 'USD' }).format(Math.round(num2));
    

    【讨论】:

      【解决方案2】:

      这应该是您正在寻找的;如果不是,我添加了第二条语句,您也可以尝试。

      document.formcalc.txtres.value = new Intl.NumberFormat('de-CH', { style: 'currency', currency: 'CHF' }).format(Math.round(num2));
      

      还有另一个解决方案:

      document.formcalc.txtres.value = Math.round(new Intl.NumberFormat('de-CH', { style: 'currency', currency: 'CHF' }).format(num2));
      

      【讨论】:

        【解决方案3】:

        只需将 num 2 提供给Math.round 并将其全部放入format()

        document.formcalc.txtres.value = new Intl.NumberFormat('de-CH', { style: 'currency', currency: 'CHF' }).format(Math.round(num2));
        

        【讨论】:

        • 如果它帮助您投票并将其标记为正确,以便它也可以帮助其他人
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-15
        • 2015-06-01
        相关资源
        最近更新 更多