Skip to content

Instantly share code, notes, and snippets.

@anandharaj-dotworld
Created September 13, 2022 10:03
Show Gist options
  • Save anandharaj-dotworld/72f5a6888887327d7e7269020847e5c6 to your computer and use it in GitHub Desktop.
Save anandharaj-dotworld/72f5a6888887327d7e7269020847e5c6 to your computer and use it in GitHub Desktop.
func kelvinToCelsius(temp uint32, n int) float64 {
// wmi return temperature Kelvin * 10, so need to divide the result by 10,
// and then minus 273.15 to get °Celsius.
t := float64(temp/10) - 273.15
n10 := math.Pow10(n)
return math.Trunc((t+0.5/n10)*n10) / n10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment