Adding addition, subtraction and multiplication operations to CurrencyUnits

This commit is contained in:
Chris Stewart 2015-12-23 11:17:04 -06:00
parent 0be96f4188
commit 7bf2d3c6e2

View file

@ -29,6 +29,18 @@ abstract class CurrencyUnit(val value:Double) {
def !=(c : CurrencyUnit) : Boolean = {
!(this == c)
}
def +(c : CurrencyUnit) : CurrencyUnit = {
Satoshis(CurrencyUnits.toSatoshis(this).value + CurrencyUnits.toSatoshis(c).value)
}
def -(c : CurrencyUnit) : CurrencyUnit = {
Satoshis(CurrencyUnits.toSatoshis(this).value - CurrencyUnits.toSatoshis(c).value)
}
def *(c : CurrencyUnit) : CurrencyUnit = {
Satoshis(CurrencyUnits.toSatoshis(this).value * CurrencyUnits.toSatoshis(c).value)
}
}
case class Satoshis(override val value: Double) extends CurrencyUnit(value) {