conversion

package
v1.32.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 1 Imported by: 0

README

Conversion

Overview

This package provides utilities for converting various units like data sizes, time, and temperature.

Functions

Data Size Conversion
  • BytesToKB(b int64) float64: Converts bytes to kilobytes.
  • KBToBytes(kb float64) int64: Converts kilobytes to bytes.
  • BytesToMB(b int64) float64: Converts bytes to megabytes.
  • MBToBytes(mb float64) int64: Converts megabytes to bytes.
  • BytesToGB(b int64) float64: Converts bytes to gigabytes.
  • GBToBytes(gb float64) int64: Converts gigabytes to bytes.
Time Conversion
  • SecondsToMinutes(s int64) float64: Converts seconds to minutes.
  • MinutesToSeconds(m int64) int64: Converts minutes to seconds.
  • MinutesToHours(m int64) float64: Converts minutes to hours.
  • HoursToMinutes(h int64) int64: Converts hours to minutes.
  • HoursToDays(h int64) float64: Converts hours to days.
  • DaysToHours(d int64) int64: Converts days to hours.
Temperature Conversion
  • CelsiusToFahrenheit(c float64) float64: Converts Celsius to Fahrenheit.
  • FahrenheitToCelsius(f float64) float64: Converts Fahrenheit to Celsius.
  • CelsiusToKelvin(c float64) float64: Converts Celsius to Kelvin.
  • KelvinToCelsius(k float64) float64: Converts Kelvin to Celsius.
  • FahrenheitToKelvin(f float64) float64: Converts Fahrenheit to Kelvin.
  • KelvinToFahrenheit(k float64) float64: Converts Kelvin to Fahrenheit.

Examples:


For examples of each function, please checkout EXAMPLES.md

Documentation

Index

Constants

View Source
const (
	KiloByte = 1_024
	MegaByte = 1_048_576
	GigaByte = 1_073_741_824
)

Data size constants

View Source
const (
	SecondsPerMinute = 60
	MinutesPerHour   = 60
	HoursPerDay      = 24
)

Time constants

View Source
const (
	CelsiusFahrenheitOffset = 32
	CelsiusToKelvinOffset   = 273.15

	FahrenheitToKelvinOffset = 459.67

	CelsiusToFahrenheitFactor = 9.0 / 5.0
	FahrenheitToCelsiusFactor = 5.0 / 9.0
)

Temperature constants

Variables

This section is empty.

Functions

func BytesToGB

func BytesToGB(b int64) float64

BytesToGB converts bytes to gigabytes It takes an integer value of bytes and returns the equivalent in gigabytes as a float64.

func BytesToKB

func BytesToKB(b int64) float64

BytesToKB converts bytes to kilobytes. It takes an integer value of bytes and returns the equivalent in kilobytes as a float64.

func BytesToMB

func BytesToMB(b int64) float64

BytesToMB converts bytes to megabytes. It takes an integer value of bytes and returns the equivalent in megabytes as a float64.

func CelsiusToFahrenheit

func CelsiusToFahrenheit(c float64) float64

CelsiusToFahrenheit converts Celsius to Fahrenheit. It takes a float64 value of Celsius and returns the equivalent in Fahrenheit as a float64.

func CelsiusToKelvin

func CelsiusToKelvin(c float64) float64

CelsiusToKelvin converts Celsius to Kelvin. It takes a float64 value of Celsius and returns the equivalent in Kelvin as a float64.

func DaysToHours

func DaysToHours(d int64) int64

DaysToHours converts days to hours. It takes an integer value of days and returns the equivalent in hours as an int64.

func FahrenheitToCelsius

func FahrenheitToCelsius(f float64) float64

FahrenheitToCelsius converts Fahrenheit to Celsius. It takes a float64 value of Fahrenheit and returns the equivalent in Celsius as a float64.

func FahrenheitToKelvin

func FahrenheitToKelvin(f float64) float64

FahrenheitToKelvin converts Fahrenheit to Kelvin. It takes a float64 value of Fahrenheit and returns the equivalent in Kelvin as a float64.

func GBToBytes

func GBToBytes(gb float64) int64

GBToBytes converts gigabytes to bytes. It takes a float64 value of gigabytes and returns the equivalent in bytes as an int64.

func HoursToDays

func HoursToDays(h int64) float64

HoursToDays converts hours to days. It takes an integer value of hours and returns the equivalent in days as a float64.

func HoursToMinutes

func HoursToMinutes(h int64) int64

HoursToMinutes converts hours to minutes. It takes an integer value of hours and returns the equivalent in minutes as an int64.

func KBToBytes

func KBToBytes(kb float64) int64

KBToBytes converts kilobytes to bytes. It takes a float64 value of kilobytes and returns the equivalent in bytes as an int64.

func KelvinToCelsius

func KelvinToCelsius(k float64) float64

KelvinToCelsius converts Kelvin to Celsius. It takes a float64 value of Kelvin and returns the equivalent in Celsius as a float64.

func KelvinToFahrenheit

func KelvinToFahrenheit(k float64) float64

KelvinToFahrenheit converts Kelvin to Fahrenheit. It takes a float64 value of Kelvin and returns the equivalent in Fahrenheit as a float64.

func MBToBytes

func MBToBytes(mb float64) int64

MBToBytes converts megabytes to bytes. It takes a float64 value of megabytes and returns the equivalent in bytes as an int64.

func MinutesToHours

func MinutesToHours(m int64) float64

MinutesToHours converts minutes to hours. It takes an integer value of minutes and returns the equivalent in hours as a float64.

func MinutesToSeconds

func MinutesToSeconds(m int64) int64

MinutesToSeconds converts minutes to seconds. It takes an integer value of minutes and returns the equivalent in seconds as an int64.

func RoundToTwoDecimals

func RoundToTwoDecimals(val float64) float64

RoundToTwoDecimals is deprecated; rounds a float64 value to two decimal places. Deprecated: Use `math.RoundDecimalPlaces(val float64, places int) float64` in the math-utils package instead.

func SecondsToMinutes

func SecondsToMinutes(s int64) float64

SecondsToMinutes converts seconds to minutes. It takes an integer value of seconds and returns the equivalent in minutes as a float64.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL