diff options
Diffstat (limited to 'model/numberNode.go')
-rw-r--r-- | model/numberNode.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/model/numberNode.go b/model/numberNode.go index e1bffd9..b61b63c 100644 --- a/model/numberNode.go +++ b/model/numberNode.go @@ -1,6 +1,9 @@ package model -import "strconv" +import ( + "fmt" + "strconv" +) type NumberNode struct { Value float64 @@ -13,3 +16,13 @@ func (n NumberNode) Type() NodeType { func (n *NumberNode) MarshalJSON() ([]byte, error) { return []byte(strconv.FormatFloat(n.Value, 'g', -1, 64)), nil } + +func (n *NumberNode) Set(v any) error { + switch v := v.(type) { + case float64: + n.Value = v + case int: + n.Value = float64(v) + } + return fmt.Errorf("%v is not number", v) +} |