git.gammaspectra.live/P2Pool/consensus/v3@v3.8.0/utils/units.go (about) 1 package utils 2 3 import "fmt" 4 5 func SiUnits(number float64, decimals int) string { 6 if number >= 1000000000 { 7 return fmt.Sprintf("%.*f G", decimals, number/1000000000) 8 } else if number >= 1000000 { 9 return fmt.Sprintf("%.*f M", decimals, number/1000000) 10 } else if number >= 1000 { 11 return fmt.Sprintf("%.*f K", decimals, number/1000) 12 } 13 14 return fmt.Sprintf("%.*f ", decimals, number) 15 } 16 17 func XMRUnits(v uint64) string { 18 const denomination = 1000000000000 19 return fmt.Sprintf("%d.%012d", v/denomination, v%denomination) 20 }