Skip to content

Commit

Permalink
fix Decimal.MIN_VALUE.toString() and release 1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Keks, Vadim Vohmjanin committed May 4, 2023
1 parent f236588 commit d286082
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Unreleased
# 1.5.2
* core: experimental Decimal class to be used for monetary values, with numerical equality (unlike BigDecimal)
* core/json: use default values for explicitly passed nulls if property is not nullable
* core/json: unwrap InvocationTargetException, so that any validation exceptions thrown from data class constructors is propagated properly
Expand Down
3 changes: 2 additions & 1 deletion core/src/Decimal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ class Decimal internal constructor(private val c: Long): Comparable<Decimal>, Nu
override fun compareTo(o: Decimal) = c.compareTo(o.c)

override fun toString(): String {
val sb = StringBuilder(if (c < 0) "-" else "").append(c.absoluteValue / CENTS)
val sb = StringBuilder((c / CENTS).toString())
val cents = (c % CENTS).absoluteValue
if (cents > 0) sb.append('.').append(cents.toString().padStart(2, '0'))
if (c > -CENTS && c < 0) sb.insert(0, '-')
return sb.toString()
}

Expand Down

0 comments on commit d286082

Please sign in to comment.