简体   繁体   English

如何使用JavaScript计算货币

[英]how to use JavaScript to calculate the currency

hi I actually trying to do calculate the two numbers,, it was working, but now I don't know how to turn the number into currency. 您好,我实际上是想计算两个数字,它确实有效,但是现在我不知道如何将数字转换为货币。 so before the number it need to show £ sign. 因此在数字前需要显示£符号。 I was researched in Google ,and i tried some things but its not actually working. 我在Google上进行了研究,并尝试了一些方法,但实际上没有用。

var name,child,result;

function setvalues()
{
   name=Number(document.getElementById("name").value);
   child=Number(document.getElementById("child").value);
}

on that name field user has to enter some number to calculate,, its was calculating but just a number not with an currency sign... I seen some of the JavaScript function to change the currency format but its not very clear... and how to add three vaules together and show in one textbox with £ sign 在该名称字段上,用户必须输入一些要计算的数字,它正在计算但只是一个不带货币符号的数字...我看到了一些JavaScript函数来更改货币格式,但它不是很清楚...并且如何将三个值加在一起并在带有£符号的文本框中显示

I am unsure of what you are trying to accomplish but I will try to answer as best I can. 我不确定您要完成什么,但我会尽力回答。 I would recommend that if you are working with currency(which can be a especially be a pain in JavaScript). 我建议如果您使用的是货币(这在JavaScript中可能尤其痛苦)。 I would recommend using a library to handle this for you. 我建议使用一个库来为您处理。 I have used accounting.js in the past and it works very well for these sorts of things: 我过去使用过accounting.js,它可以很好地用于以下方面:

http://josscrowcroft.github.io/accounting.js/ http://josscrowcroft.github.io/accounting.js/

If you update your question with more information I will update my answer. 如果您使用更多信息更新您的问题,我将更新我的答案。

UPDATE 更新

Try this: http://codepen.io/anon/pen/BjIHn/ . 试试这个: http : //codepen.io/anon/pen/BjIHn/ It should produces the output you are wanting. 它应该产生您想要的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM