Skip to content

Money rounding mode #216

@bytecodeguru

Description

@bytecodeguru

Looking at the code I've noticed that Money.toString uses the explicit rounding mode HALF_EVEN, while Money.toFormattedString does not. Is this the intended behaviour?

Speaking about rounding modes, I'd find useful a method to apply rounding to a Money instance. What I'm doing in my code right now is something like this:

implicit class MoneyOps(m: Money) {
  def rounded: Money = Money(
    value = m.amount.setScale(m.currency.formatDecimals, BigDecimal.RoundingMode.HALF_EVEN),
    currency = m.currency
  )
}

This may be useful to apply rounding in calculations on purpose.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions