mirror of
https://github.com/LBRYFoundation/lbcutil.git
synced 2025-08-23 17:47:30 +00:00
parent
8180321217
commit
40ba1daf69
2 changed files with 12 additions and 0 deletions
|
@ -89,6 +89,11 @@ func (a Amount) ToUnit(u AmountUnit) float64 {
|
||||||
return float64(a) / math.Pow10(int(u+8))
|
return float64(a) / math.Pow10(int(u+8))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToBTC is the equivalent of calling ToUnit with AmountBTC.
|
||||||
|
func (a Amount) ToBTC() float64 {
|
||||||
|
return a.ToUnit(AmountBTC)
|
||||||
|
}
|
||||||
|
|
||||||
// Format formats a monetary amount counted in bitcoin base units as a
|
// Format formats a monetary amount counted in bitcoin base units as a
|
||||||
// string for a given unit. The conversion will succeed for any unit,
|
// string for a given unit. The conversion will succeed for any unit,
|
||||||
// however, known units will be formated with an appended label describing
|
// however, known units will be formated with an appended label describing
|
||||||
|
|
|
@ -185,6 +185,13 @@ func TestAmountUnitConversions(t *testing.T) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify that Amount.ToBTC works as advertised.
|
||||||
|
f1 := test.amount.ToUnit(AmountBTC)
|
||||||
|
f2 := test.amount.ToBTC()
|
||||||
|
if f1 != f2 {
|
||||||
|
t.Errorf("%v: ToBTC does not match ToUnit(AmountBTC): %v != %v", test.name, f1, f2)
|
||||||
|
}
|
||||||
|
|
||||||
// Verify that Amount.String works as advertised.
|
// Verify that Amount.String works as advertised.
|
||||||
s1 := test.amount.Format(AmountBTC)
|
s1 := test.amount.Format(AmountBTC)
|
||||||
s2 := test.amount.String()
|
s2 := test.amount.String()
|
||||||
|
|
Loading…
Add table
Reference in a new issue