github.com/searKing/golang/go@v1.2.74/encoding/prettyjson/number.go (about) 1 // Copyright 2023 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package prettyjson 6 7 import ( 8 "reflect" 9 "strconv" 10 ) 11 12 var numberType = reflect.TypeOf(Number("")) 13 14 // A Number represents a JSON number literal. 15 type Number string 16 17 // String returns the literal text of the number. 18 func (n Number) String() string { return string(n) } 19 20 // Float64 returns the number as a float64. 21 func (n Number) Float64() (float64, error) { 22 return strconv.ParseFloat(string(n), 64) 23 } 24 25 // Int64 returns the number as an int64. 26 func (n Number) Int64() (int64, error) { 27 return strconv.ParseInt(string(n), 10, 64) 28 }