2021-10-26 10:31:31 +00:00
|
|
|
package accounting
|
|
|
|
|
|
|
|
import "github.com/nspcc-dev/neofs-api-go/v2/accounting"
|
|
|
|
|
|
|
|
// Decimal represents decimal number for accounting operations.
|
|
|
|
//
|
2022-03-12 16:15:26 +00:00
|
|
|
// Decimal is mutually compatible with github.com/nspcc-dev/neofs-api-go/v2/accounting.Decimal
|
2022-03-17 13:45:26 +00:00
|
|
|
// message. See ReadFromV2 / WriteToV2 methods.
|
2022-03-12 16:15:26 +00:00
|
|
|
//
|
|
|
|
// Instances can be created using built-in var declaration.
|
|
|
|
//
|
|
|
|
// Note that direct typecast is not safe and may result in loss of compatibility:
|
|
|
|
// _ = Decimal(accounting.Decimal{}) // not recommended
|
|
|
|
type Decimal accounting.Decimal
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-03-17 13:45:26 +00:00
|
|
|
// ReadFromV2 reads Decimal from the accounting.Decimal message.
|
2021-10-26 10:31:31 +00:00
|
|
|
//
|
2022-03-17 13:45:26 +00:00
|
|
|
// See also WriteToV2.
|
|
|
|
func (d *Decimal) ReadFromV2(m accounting.Decimal) {
|
2022-03-12 16:15:26 +00:00
|
|
|
*d = Decimal(m)
|
2021-10-26 10:31:31 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 13:45:26 +00:00
|
|
|
// WriteToV2 writes Decimal to the accounting.Decimal message.
|
2022-03-12 16:15:26 +00:00
|
|
|
// The message must not be nil.
|
2021-10-26 10:31:31 +00:00
|
|
|
//
|
2022-03-17 13:45:26 +00:00
|
|
|
// See also ReadFromV2.
|
|
|
|
func (d Decimal) WriteToV2(m *accounting.Decimal) {
|
2022-03-12 16:15:26 +00:00
|
|
|
*m = (accounting.Decimal)(d)
|
2021-10-26 10:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Value returns value of the decimal number.
|
2022-03-12 16:15:26 +00:00
|
|
|
//
|
|
|
|
// Zero Decimal has zero value.
|
|
|
|
//
|
|
|
|
// See also SetValue.
|
|
|
|
func (d Decimal) Value() int64 {
|
|
|
|
return (*accounting.Decimal)(&d).GetValue()
|
2021-10-26 10:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetValue sets value of the decimal number.
|
2022-03-12 16:15:26 +00:00
|
|
|
//
|
|
|
|
// See also Value.
|
2021-10-26 10:31:31 +00:00
|
|
|
func (d *Decimal) SetValue(v int64) {
|
|
|
|
(*accounting.Decimal)(d).SetValue(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Precision returns precision of the decimal number.
|
2022-03-12 16:15:26 +00:00
|
|
|
//
|
|
|
|
// Zero Decimal has zero precision.
|
|
|
|
//
|
|
|
|
// See also SetPrecision.
|
|
|
|
func (d Decimal) Precision() uint32 {
|
|
|
|
return (*accounting.Decimal)(&d).GetPrecision()
|
2021-10-26 10:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetPrecision sets precision of the decimal number.
|
2022-03-12 16:15:26 +00:00
|
|
|
//
|
|
|
|
// See also Precision.
|
2021-10-26 10:31:31 +00:00
|
|
|
func (d *Decimal) SetPrecision(p uint32) {
|
|
|
|
(*accounting.Decimal)(d).SetPrecision(p)
|
|
|
|
}
|