tweak: pretty print with more precision
This commit is contained in:
parent
a1595935d6
commit
06602cd291
|
@ -10,13 +10,13 @@ import (
|
||||||
func PrettyPrintInt(n int) {
|
func PrettyPrintInt(n int) {
|
||||||
switch {
|
switch {
|
||||||
case math.Abs(float64(n)) >= 1_000_000_000_000:
|
case math.Abs(float64(n)) >= 1_000_000_000_000:
|
||||||
fmt.Printf("%dT", n/1_000_000_000_000)
|
fmt.Printf("%.2fT", float64(n)/1_000_000_000_000.0)
|
||||||
case math.Abs(float64(n)) >= 1_000_000_000:
|
case math.Abs(float64(n)) >= 1_000_000_000:
|
||||||
fmt.Printf("%dB", n/1_000_000_000)
|
fmt.Printf("%.2fB", float64(n)/1_000_000_000.0)
|
||||||
case math.Abs(float64(n)) >= 1_000_000:
|
case math.Abs(float64(n)) >= 1_000_000:
|
||||||
fmt.Printf("%dM", n/1_000_000)
|
fmt.Printf("%.2fM", float64(n)/1_000_000.0)
|
||||||
case math.Abs(float64(n)) >= 1_000:
|
case math.Abs(float64(n)) >= 1_000:
|
||||||
fmt.Printf("%dK", n/1_000)
|
fmt.Printf("%.2fK", float64(n)/1_000.0)
|
||||||
default:
|
default:
|
||||||
fmt.Printf("%df", n)
|
fmt.Printf("%df", n)
|
||||||
}
|
}
|
||||||
|
@ -25,24 +25,24 @@ func PrettyPrintInt(n int) {
|
||||||
func PrettyPrintFloat(f float64) {
|
func PrettyPrintFloat(f float64) {
|
||||||
switch {
|
switch {
|
||||||
case math.Abs(f) >= 1_000_000_000_000:
|
case math.Abs(f) >= 1_000_000_000_000:
|
||||||
fmt.Printf("%.1fT", f/1_000_000_000_000)
|
fmt.Printf("%.2fT", f/1_000_000_000_000)
|
||||||
case math.Abs(f) >= 1_000_000_000:
|
case math.Abs(f) >= 1_000_000_000:
|
||||||
fmt.Printf("%.1fB", f/1_000_000_000)
|
fmt.Printf("%.2fB", f/1_000_000_000)
|
||||||
case math.Abs(f) >= 1_000_000:
|
case math.Abs(f) >= 1_000_000:
|
||||||
fmt.Printf("%.1fM", f/1_000_000)
|
fmt.Printf("%.2fM", f/1_000_000)
|
||||||
case math.Abs(f) >= 1_000:
|
case math.Abs(f) >= 1_000:
|
||||||
fmt.Printf("%.1fK", f/1_000)
|
fmt.Printf("%.2fK", f/1_000)
|
||||||
|
|
||||||
case math.Abs(f) <= 0.0001:
|
case math.Abs(f) <= 0.0001:
|
||||||
fmt.Printf("%.5f", f)
|
fmt.Printf("%.6f", f)
|
||||||
case math.Abs(f) <= 0.001:
|
case math.Abs(f) <= 0.001:
|
||||||
fmt.Printf("%.4f", f)
|
fmt.Printf("%.5f", f)
|
||||||
case math.Abs(f) <= 0.01:
|
case math.Abs(f) <= 0.01:
|
||||||
fmt.Printf("%.3f", f)
|
fmt.Printf("%.4f", f)
|
||||||
case math.Abs(f) <= 0.1:
|
case math.Abs(f) <= 0.1:
|
||||||
fmt.Printf("%.2f", f)
|
fmt.Printf("%.3f", f)
|
||||||
default:
|
default:
|
||||||
fmt.Printf("%.1f", f)
|
fmt.Printf("%.2f", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user