简体   繁体   中英

Convert European price to another format

I'm trying to convert several European price formats to other formats. The European format is like this:

€1.795,00

I need to convert it to

€1,795.00

I'm using this script http://josscrowcroft.github.io/money.js/ to convert currencies from one to another. However when when it reads something like €1.795,00 , it thinks its €1.79 which is problematic.

Is there a method which would convert any decimals to dots and vice versa? Or is there some other alternative method to achieve what I need.

There might be a cleaner solution but this is the easy one:

str.replace(",",";");
str.replace(".",",");
str.replace(";",".");
str = "€1.795,00";
str = str.replace(",",";").replace(".",",").replace(";",".");

Now, str = "€1,795.00";

str = str.replace(",",";").replace(".",",").replace(";",".");

Now, str = "€1.795,00";

Thanks for the reply everyone, actually I found the solution I was looking for. Here, for anyone else looking for the answer to this.

I'm using money.js as mentioned above to convert currencies and it so happens another script called accounting.js is also necessary if you want to format currencies.

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

If you have something like €1.700,00 , use method accounting.unformat from accounting.js and you'll get this 1700

Then simply convert it with money.js :)

btw, the function explanation is near the bottom of the link

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