mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
fix: fixedpoint MarshalJson on inf
This commit is contained in:
parent
51d7c1b9ad
commit
b52598d1ad
|
@ -242,6 +242,9 @@ func (v Value) MarshalYAML() (interface{}, error) {
|
|||
}
|
||||
|
||||
func (v Value) MarshalJSON() ([]byte, error) {
|
||||
if v.IsInf() {
|
||||
return []byte("\"" + v.String() + "\""), nil
|
||||
}
|
||||
return []byte(v.FormatString(DefaultPrecision)), nil
|
||||
}
|
||||
|
||||
|
@ -446,6 +449,10 @@ func NewFromInt(val int64) Value {
|
|||
return Value(val * DefaultPow)
|
||||
}
|
||||
|
||||
func (a Value) IsInf() bool {
|
||||
return a == PosInf || a == NegInf
|
||||
}
|
||||
|
||||
func (a Value) MulExp(exp int) Value {
|
||||
return Value(int64(float64(a) * math.Pow(10, float64(exp))))
|
||||
}
|
||||
|
|
|
@ -1033,7 +1033,7 @@ func (x Value) Compare(y Value) int {
|
|||
}
|
||||
|
||||
func (v Value) MarshalYAML() (interface{}, error) {
|
||||
return v.FormatString(8), nil
|
||||
return v.FormatString(8), nil
|
||||
}
|
||||
|
||||
func (v *Value) UnmarshalYAML(unmarshal func(a interface{}) error) (err error) {
|
||||
|
@ -1061,6 +1061,9 @@ func (v *Value) UnmarshalYAML(unmarshal func(a interface{}) error) (err error) {
|
|||
|
||||
// FIXME: should we limit to 8 prec?
|
||||
func (v Value) MarshalJSON() ([]byte, error) {
|
||||
if v.IsInf() {
|
||||
return []byte("\"" + v.String() + "\""), nil
|
||||
}
|
||||
return []byte(v.FormatString(8)), nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user