convert.go 936 字节
package utils

import "strconv"

type NumberString string

func (s NumberString) String() string {
	return string(s)
}

func (s NumberString) Int() (int, error) {
	v, err := strconv.Atoi(s.String())
	return v, err
}

func (s NumberString) MustInt() int {
	v, _ := s.Int()
	return v
}

func (s NumberString) UInt32() (uint32, error) {
	v, err := strconv.Atoi(s.String())
	return uint32(v), err
}

func (s NumberString) MustUInt32() uint32 {
	v, _ := s.UInt32()
	return v
}

func (s NumberString) Int64() (int64, error) {
	v, err := strconv.ParseInt(s.String(), 10, 64)
	return v, err
}

func (s NumberString) MustInt64() int64 {
	v, _ := s.Int64()
	return v
}

func (s NumberString) Float64() (float64, error) {
	return strconv.ParseFloat(s.String(), 64)
}

func (s NumberString) MustFloat64() float64 {
	v, _ := strconv.ParseFloat(s.String(), 64)
	return v
}

func NewNumberString(str string) NumberString {
	return NumberString(str)
}