123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- // Author : Eric Kim
- // Build Date : 23 Jul 2018 Last Update 02 Aug 2018
- // End-Agent for Passcon Multi OS go binding with Windows, MacOS, iOS, and Android
- // All rights are reserved.
- package etc
- import (
- "fmt"
- "reflect"
- "strconv"
- )
- func DecimalToInt(decimal string) int {
- if tmp, err := strconv.ParseFloat(decimal, 4); err == nil {
- return int(tmp)
- } else {
- ErrLog("LJLJLJLJIUU-decimal unacceptable", err)
- return 999999999
- }
- }
- func DecimalToFloat64(decimal string) float64 {
- if num, err := strconv.ParseFloat(decimal, 4); err == nil {
- return num
- } else {
- ErrLog("UYTIUYKHKIU-decimal unacceptable", err)
- return 999999999999.9999
- }
- }
- func NumToDecimal(num interface{}, precision string) string {
- switch reflect.TypeOf(num).String() {
- case "int":
- tmp := float64(num.(int))
- return fmt.Sprintf("%"+precision+"f", tmp)
- case "int32":
- tmp := float64(num.(int))
- return fmt.Sprintf("%"+precision+"f", tmp)
- case "int64":
- tmp := float64(num.(int))
- return fmt.Sprintf("%"+precision+"f", tmp)
- case "float32":
- return fmt.Sprintf("%"+precision+"f", num)
- case "float64":
- return fmt.Sprintf("%"+precision+"f", num)
- default:
- return "Out of Range"
- }
- }
- func NumToStr(num interface{}) string {
- numType := reflect.TypeOf(num).String()
- switch reflect.TypeOf(num).String() {
- case "int":
- return fmt.Sprintf("%d", num)
- case "int32":
- return fmt.Sprintf("%d", num)
- case "int64":
- return fmt.Sprintf("%d", num)
- case "float32":
- return fmt.Sprintf("%f", num)
- case "float64":
- return fmt.Sprintf("%f", num)
- default:
- return numType + " is Out of Range"
- }
- }
- func StrToInt(num string) int {
- if i, err := strconv.Atoi(num); err == nil {
- return i
- } else {
- ErrLog("PIOUKHBJJCHYT-'Integer' unacceptable", err)
- return 0
- }
- }
- func StrToFloat(num string, decimalP int) float64 {
- if f, err := strconv.ParseFloat(num, decimalP); err == nil {
- return f
- } else {
- ErrLog("UYTIKHKYOUJ- 'Float' unacceptable", err)
- return 0
- }
- }
|