FlexDXCluster/utils.go

35 lines
704 B
Go
Raw Normal View History

2024-09-23 16:24:50 +07:00
package main
import (
"log"
"math"
"strconv"
)
func FreqMhztoHz(freq string) string {
frequency, err := strconv.ParseFloat(freq, 64)
if err != nil {
log.Println("could not convert frequency string to int", err)
}
frequency = frequency / 1000
return strconv.FormatFloat(frequency, 'f', 6, 64)
}
func FreqHztoMhz(freq string) string {
frequency, err := strconv.ParseFloat(freq, 64)
if err != nil {
log.Println("could not convert frequency string to int", err)
}
frequency = frequency * 1000
return strconv.FormatFloat(frequency, 'f', 6, 64)
}
func roundFloat(val float64, precision uint) float64 {
ratio := math.Pow(10, float64(precision))
return math.Round(val*ratio) / ratio
}