DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Celsius <-> Fahrenheit in PowerShell  (Read 13,475 times)

Tuxman

  • OMG not him again!
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,522
    • Participated in NANY Challenge Seven Times
Celsius <-> Fahrenheit in PowerShell
« on: November 22, 2022, 11:15 PM »
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:

Code
> FtoC(32)
32 °F = 0 °C
> CtoF(0)
0 °C = 32 °F
I bet when Cheetahs race and one of them cheats, the other one goes "Man, you're such a Cheetah!" and they laugh & eat a zebra or whatever.

Original address: https://www.donationcoder.com/forum/index.php?topic=52828.0