As the title -- although discretely -- hints, I only pay with dollars.
The challenge
Write a function/program that takes a string as input, which is a monetary value preceded by a symbol. ex) £4.99
. Then, return that same amount converted to USD.
Input
You will get a string as input. It will have the currency symbol followed by a number with two decimal places (which could be .00
). There will either be decimal points .
and/or commas ,
separating the number. The following currency symbols will come in the inputs:
Euro: €
Pound Sterling: £
Yuan Renminbi: ¥
Also, there will be a comma or decimal point depending on the currency to separate the 'dollars' from the 'cents':
Euro: #.###,##
Pound Sterling: #,###.##
Yuan Renminbi: #,###.##
Output
You will convert the input from the currency determined by the symbol to USD, rounding to two decimal places. The output will be in the format $#,###.##
, and there will of course be more numbers on the left of the output if need be (EDIT: this means that there is an arbitrary number of commas in the output, just like in the input). The currency exchange rate we will be using are below.
You can assume that the input contains a symbol that is only one of the above (€ £ ¥ . ,
)--that it is always valid.
Exchange rates
€1 : $1.10
£1 : $1.37
¥1 : $0.15
Examples
Input:
€1,37
£4.00
¥2,782,122.78
Respective output:
$1.51
$5.48
$417,318.42
Final words
- If you use one of the above symbols (€, £, ¥), you may count them as 1 byte
- This is code golf, so shortest code in bytes wins!
10,0000.15
) \$\endgroup\$ – Not that Charles Jun 24 '16 at 14:27£1 : $1.51
xD \$\endgroup\$ – Kevin Cruijssen Jun 24 '16 at 14:271.37 * 1.10 = 1,507 = 1,51
(so not1.52
) and4.00 * 1.37 = 5.48
(not5.50
) and2782122.78 * 0.15 = 417318.417 = 417318.42
(not420165.06
)... :S \$\endgroup\$ – Kevin Cruijssen Jun 24 '16 at 15:00