how to show float value of decimal.Decimal during delve mozilla rr(record-replay) replay session

Viewed 279

How can we easily see the float value of decimal.Decimal value in delve session. especially in dlv replay session recorded by mozilla rr.

(dlv) args
underlyingPx = github.com/shopspring/decimal.Decimal {value: ("*math/big.Int")(0xc00101cca0), exp: 3}

(dlv) p underlyingPx
github.com/shopspring/decimal.Decimal {
    value: *math/big.Int {
        neg: false,
        abs: math/big.nat len: 1, cap: 1, [8],},
    exp: 3,}

Thanks

2 Answers

According to source code of Decimal there is a method to receive this information:

// Float64 returns the nearest float64 value for d and a bool indicating
// whether f represents d exactly.
// For more details, see the documentation for big.Rat.Float64
func (d Decimal) Float64() (f float64, exact bool) {
    return d.Rat().Float64()
}

In provided example it will be enough to just call this method:

(dlv) p underlyingPx.Float64()
Related