# Convert Currency To Your Own (Currency Exchange Rate)

Sometime, your partner tells you the amount of his currency, and you want to exchange it to your own, how will you do that? Access Google, search an exchange rate website, input your amount, select the currency type, and record the result? It’s too complex. Now, I will show you the much more easier way via PowerShell.

Create a function in your PowerShell profile, it’s the code:

function ConvertTo-MyCurrency {
param(
# Default: 1
[Parameter(Mandatory=false)]         [ValidateScript({_ -gt 0})]
Amount = 1,          # Default: USD         [Parameter(Mandatory=false)]
[string]From="USD",          # Default: CNY         [Parameter(Mandatory=false)]
[string]To="CNY"     )     if (From -eq To) {         Write-Warning -Message "Idiot! You can't convert From to To by yourself?!"         break     }     url = "https://finance.google.cn/finance/converter?a=Amount&from=From&to=To"     result = (Invoke-WebRequest -Uri url).content -replace "(.*\n)*.*bld>|\sTo.*(.*\n)*"
Write-Host "tAmount From = result To"
}


In this function, up to 170 currency types are supported, and it’s very easy to use. Let’s look at some samples.
1. Quick converting. I’m in China, and the most frequent foreign currency for me is US dollar, so I will check the latest rate by this:

PS D:\Scripts> ConvertTo-MyCurrency
1 USD = 6.3416 CNY


2. Specify the currency type. It’s an example:

PS D:\Scripts> ConvertTo-MyCurrency -From KWD -To VND -Amount 1
1 KWD = 76365.0686 VND


3. Of cource, if you want to convert A to A, the result won’t be friendly.

PS D:\Scripts> ConvertTo-MyCurrency -From KWD -To KWD -Amount 1
WARNING: Idiot! You can't convert KWD to KWD by yourself?!
`

OK, enjoy it!