2017-10-24 07:09:17 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"strconv"
|
2017-10-24 09:23:56 +00:00
|
|
|
"regexp"
|
2017-10-24 07:09:17 +00:00
|
|
|
)
|
|
|
|
|
2017-11-08 02:43:25 +00:00
|
|
|
func StringToInt64(str string) int64 {
|
|
|
|
n, _ := strconv.ParseInt(str, 10,64)
|
2017-10-24 07:09:17 +00:00
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func round(num float64) int {
|
|
|
|
return int(num + math.Copysign(0.5, num))
|
|
|
|
}
|
|
|
|
|
2017-11-08 02:43:25 +00:00
|
|
|
func ToFixed(num float64, precision int) float64 {
|
2017-10-24 07:09:17 +00:00
|
|
|
output := math.Pow(10, float64(precision))
|
|
|
|
return float64(round(num*output)) / output
|
|
|
|
}
|
2017-10-24 09:23:56 +00:00
|
|
|
|
|
|
|
func ExtractInBracket(str string) string {
|
|
|
|
regex := regexp.MustCompile(`\[(.*?)\]`)
|
|
|
|
return regex.FindStringSubmatch(str)[1]
|
|
|
|
}
|