Skip to content

Commit

Permalink
bugfix #818 Fix crash on input.
Browse files Browse the repository at this point in the history
  • Loading branch information
toastkidjp committed Jun 10, 2023
1 parent 18c4c3e commit a171d5c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions loan/src/main/java/jp/toastkid/loan/view/LoanCalculatorUi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ fun LoanCalculatorUi() {
"${(index / 12) + 1} ${(index % 12) + 1}(${index + 1})",
modifier = Modifier.weight(0.4f)
)
Text(it.principal.roundToInt().toString(), modifier = Modifier.weight(1f))
Text(it.interest.roundToInt().toString(), modifier = Modifier.weight(1f))
Text(roundToIntSafely(it.principal), modifier = Modifier.weight(1f))
Text(roundToIntSafely(it.interest), modifier = Modifier.weight(1f))
Text(it.amount.toString(), modifier = Modifier.weight(1f))
}
}
Expand All @@ -221,6 +221,9 @@ fun LoanCalculatorUi() {
}
}

private fun roundToIntSafely(d: Double) =
if (d.isNaN()) "0" else d.roundToInt().toString()

@Composable
private fun makeTextFieldColors() = TextFieldDefaults.colors(
focusedTextColor = MaterialTheme.colorScheme.onSurface,
Expand Down

0 comments on commit a171d5c

Please sign in to comment.