ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Coding Snacks

Celsius <-> Fahrenheit in PowerShell

(1/1)

Tuxman:
I had a request to myself: I want to convert Fahrenheit <-> Celsius on Windows without having to install a whole bunch of GNU utilities (which would have been the easiest way, I presume). So I wrote a converter for Powershell which I use anyway. :)


--- Code: PowerShell ---function FtoC([double]$fahrenheit) {        $celsius = ($fahrenheit - 32) * (5/9)        "{0} °F = {1} °C" -f $fahrenheit,[math]::Round($celsius,3)} function CtoF([double]$celsius) {        $fahrenheit = ($celsius * (9/5)) + 32        "{0} °C = {1} °F" -f $celsius,[math]::Round($fahrenheit,3)}
Usage:


--- ---> FtoC(32)
32 °F = 0 °C
> CtoF(0)
0 °C = 32 °F

Navigation

[0] Message Index

Go to full version