upgrade:float64 formatting method
This commit is contained in:
1 parent
7140ff8a3a
commit
2d11163ce5
2 files changed
+10
-3
No files matched your search
+9
-1
@@ -1,7 +1,15 @@
|
||||
package tools
|
||||
|
||||
import "strconv"
|
||||
import (
|
||||
"math"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func Float64ToString(e float64) string {
|
||||
return strconv.FormatFloat(e, 'E', -1, 64)
|
||||
}
|
||||
|
||||
func Round(f float64, n int) float64 {
|
||||
pow10_n := math.Pow10(n)
|
||||
return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n // TODO +0.5 是为了四舍五入,如果不希望这样去掉这个
|
||||
}
|
||||
Reference in new issue
Block a user