简体   繁体   中英

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.

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

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). 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:

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/ . It should produces the output you are wanting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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