Skip to content

Commit 73c7bc8

Browse files
committed
fix #180, add missing methods to jsoniter.Number
1 parent 4de15a3 commit 73c7bc8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

feature_json_number.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
package jsoniter
22

3-
import "encoding/json"
3+
import (
4+
"encoding/json"
5+
"strconv"
6+
)
47

58
type Number string
69

10+
// String returns the literal text of the number.
11+
func (n Number) String() string { return string(n) }
12+
13+
// Float64 returns the number as a float64.
14+
func (n Number) Float64() (float64, error) {
15+
return strconv.ParseFloat(string(n), 64)
16+
}
17+
18+
// Int64 returns the number as an int64.
19+
func (n Number) Int64() (int64, error) {
20+
return strconv.ParseInt(string(n), 10, 64)
21+
}
22+
723
func CastJsonNumber(val interface{}) (string, bool) {
824
switch typedVal := val.(type) {
925
case json.Number:

0 commit comments

Comments
 (0)