Skip to content

Commit

Permalink
marshal-text (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaydubina authored Nov 29, 2024
1 parent 042a8c8 commit 2e33570
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fp3/fpdecimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func (v *Decimal) UnmarshalJSON(b []byte) (err error) {

func (v Decimal) MarshalJSON() ([]byte, error) { return []byte(v.String()), nil }

func (v *Decimal) UnmarshalText(b []byte) (err error) {
v.v, err = fpdecimal.ParseFixedPointDecimal(b, fractionDigits)
return err
}

func (v Decimal) MarshalText() ([]byte, error) { return []byte(v.String()), nil }

func (a Decimal) Scaled() int64 { return a.v }

func (a Decimal) Float32() float32 { return float32(a.v) / float32(multiplier) }
Expand Down
7 changes: 7 additions & 0 deletions fp6/fpdecimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func (v *Decimal) UnmarshalJSON(b []byte) (err error) {

func (v Decimal) MarshalJSON() ([]byte, error) { return []byte(v.String()), nil }

func (v *Decimal) UnmarshalText(b []byte) (err error) {
v.v, err = fpdecimal.ParseFixedPointDecimal(b, fractionDigits)
return err
}

func (v Decimal) MarshalText() ([]byte, error) { return []byte(v.String()), nil }

func (a Decimal) Scaled() int64 { return a.v }

func (a Decimal) Float32() float32 { return float32(a.v) / float32(multiplier) }
Expand Down

0 comments on commit 2e33570

Please sign in to comment.