As the title -- although discretely -- hints, I only pay with dollars.
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.
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:
Pound Sterling: £
Yuan Renminbi: ¥
Also, there will be a comma or decimal point depending on the currency to separate the 'dollars' from the 'cents':
Pound Sterling: #,###.##
Yuan Renminbi: #,###.##
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.
€1 : $1.10 £1 : $1.37 ¥1 : $0.15
Input: €1,37 £4.00 ¥2,782,122.78 Respective output: $1.51 $5.48 $417,318.42
- 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!