astro/tools/format.go

25 lines
444 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tools
import (
"fmt"
"math"
)
func Format(val float64, typed uint8) string {
belowZero := false
if val < 0 {
belowZero = true
val = -val
}
degree := math.Floor(val)
min := math.Floor((val - degree) * 60)
sec := (val - degree - min/60) * 3600
if belowZero {
degree = -degree
}
if typed == 0 {
return fmt.Sprintf("%.0f°%.0f%.2f″", degree, min, sec)
}
return fmt.Sprintf("%.0fh%.0fm%.2fs", degree, min, sec)
}