Commit 999d400f by feidy

string float64 int utils

parent 0c4b51e8
package utils
import "strconv"
import (
"fmt"
"strconv"
)
// int to string
func IntToString(a int) string {
return strconv.Itoa(a)
}
func Float64ToString(a float64) string {
return strconv.FormatFloat(a, 'E', -1, 64)
// float64 to string
func Float64ToString(a float64, point int) string {
a = FloatRound(a, point)
return strconv.FormatFloat(a, 'f', -1, 64)
}
// string to int
func StringToInt(s string) int {
i, _ := strconv.Atoi(s)
return i
}
// string to float64
func StringToFloat64(s string) float64 {
f, _ := strconv.ParseFloat(s, 64)
return f
}
// float round point
func FloatRound(f float64, n int) float64 {
format := "%." + strconv.Itoa(n) + "f"
res, _ := strconv.ParseFloat(fmt.Sprintf(format, f), 64)
return res
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment