Cosmetic change to Amount to display decimal places

This commit is contained in:
Richard Green 2016-03-18 13:45:22 +00:00
parent 3c4ce0a8fe
commit 5e3ff4238f
2 changed files with 9 additions and 1 deletions

View File

@ -58,7 +58,7 @@ data class Amount(val pennies: Long, val currency: Currency) : Comparable<Amount
operator fun div(other: Int): Amount = Amount(pennies / other, currency)
operator fun times(other: Int): Amount = Amount(Math.multiplyExact(pennies, other.toLong()), currency)
override fun toString(): String = currency.currencyCode + " " + (BigDecimal(pennies) / BigDecimal(100)).toPlainString()
override fun toString(): String = currency.currencyCode + " " + (BigDecimal(pennies).divide(BigDecimal(100))).setScale(2).toPlainString()
override fun compareTo(other: Amount): Int {
checkCurrency(other)

View File

@ -10,9 +10,17 @@ package core
import org.junit.Test
import java.time.LocalDate
import java.util.*
class FinanceTypesTest {
@Test
fun `make sure Amount has decimal places`() {
var x = Amount(1, Currency.getInstance("USD"))
assert("0.01" in x.toString())
}
@Test
fun `schedule generator 1`() {
var ret = BusinessCalendar.createGenericSchedule(startDate = LocalDate.of(2014, 11, 25), period = Frequency.Monthly, noOfAdditionalPeriods = 3)