Skip to content

Commit 57b6428

Browse files
authored
use a formatter to display Btc/MilliBtc amounts
Display a fixed number of digits after the comma, instead of the default which may even use the exponent display occasionnally. Please double check the `MilliBtc` case as it's easy to get it wrong.
1 parent 522ff59 commit 57b6428

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/main/scala/fr/acinq/bitcoin/scalacompat/BtcAmount.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ case class MilliBtc(private val underlying: BigDecimal) extends BtcAmount with O
5252
def toBigDecimal: BigDecimal = underlying
5353
def toDouble: Double = underlying.toDouble
5454
def toLong: Long = underlying.toLong
55-
override def toString = s"$underlying mBTC"
55+
override def toString = f"$underlying%1.5f mBTC"
5656
// @formatter:on
5757
}
5858

@@ -82,12 +82,12 @@ case class Btc(private val underlying: BigDecimal) extends BtcAmount with Ordere
8282
def toBigDecimal: BigDecimal = underlying
8383
def toDouble: Double = underlying.toDouble
8484
def toLong: Long = underlying.toLong
85-
override def toString = s"$underlying BTC"
85+
override def toString = f"$underlying%1.8f BTC"
8686
// @formatter:on
8787
}
8888

8989
object BtcAmount {
9090
val Coin = 100000000L
9191
val Cent = 1000000L
9292
val MaxMoney: Double = 21e6 * Coin
93-
}
93+
}

0 commit comments

Comments
 (0)