feat(core): hideZeroFractionDigits option — hide decimals when zero#13
Merged
Conversation
Adds a boolean `hideZeroFractionDigits` field to `CurrencyFormatOptions`
(default `false`, backward-compatible). When `true`, the fractional part is
suppressed in `formatWithOptions` / `formatAmountWithOptions` if and only if
every digit in the rounded fraction is zero ("$34.00" → "$34"), while any
non-zero fraction keeps full precision ("$34.20" stays "$34.20"). The option
wins over `minFractionDigits`. Covered by 16 commonTest cases across USD,
BHD, JPY, EUR/German locale, negative amounts, grouping, and zero amounts.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Expose CurrencyFormatOptions to kurrency-deci by adding two extension functions on CurrencyFormatter that accept a Deci amount and delegate to the existing String-based formatWithOptions in core. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…nt from JSON Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces an opt-in CurrencyFormatOptions.hideZeroFractionDigits flag to suppress the decimal separator and fractional digits when the fractional portion is all zeros, while leaving non-zero fractions unchanged. It updates the common formatting engine to apply the behavior after precision resolution and rounding, adds Deci overloads for options-based formatting, and expands cross-platform test coverage including serialization.
Changes:
- Add
hideZeroFractionDigitstoCurrencyFormatOptions(serializable, defaultfalse) and apply it during numeric reassembly inCurrencyFormatter. - Add
CurrencyFormatter.formatWithOptions(amount: Deci, …)overloads inkurrency-deci. - Add common tests for hide/keep behavior, locale differences, rounding behavior, and serialization defaults/round-trip.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| kurrency-core/src/commonMain/kotlin/org/kimplify/kurrency/CurrencyFormatOptions.kt | Adds hideZeroFractionDigits option to the serializable options model and builder. |
| kurrency-core/src/commonMain/kotlin/org/kimplify/kurrency/CurrencyFormatter.kt | Drops the fractional part + decimal separator when the fraction is all zeros and the option is enabled. |
| kurrency-core/src/commonTest/kotlin/org/kimplify/kurrency/HideZeroFractionDigitsTest.kt | Adds cross-locale/common tests covering hide/keep logic, rounding, negatives, and 0-fraction currencies. |
| kurrency-core/src/commonTest/kotlin/org/kimplify/kurrency/serialization/CurrencyFormatOptionsSerializerTest.kt | Adds serialization round-trip and defaulting coverage for the new option. |
| kurrency-deci/src/commonMain/kotlin/org/kimplify/kurrency/deci/DeciExtensions.kt | Adds Deci overloads for options-based formatting via CurrencyFormatter. |
| kurrency-deci/src/commonTest/kotlin/org/kimplify/kurrency/deci/DeciHideZeroFractionDigitsTest.kt | Adds Deci-specific tests validating hide/keep and rounding-to-zero behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…eci) overloads Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5. Adds an opt-in
CurrencyFormatOptions.hideZeroFractionDigitsflag: when the fractional part is all zeros it's dropped, while non-zero fractions keep full precision.34.00$3434.20$34.2034.88$34.88Design
CurrencyFormatter.formatWithOptionsengine: after the number is rounded and split, an all-zero fractional part is dropped (and so is the decimal separator).34.004 → $34) and after min/max resolution (so it wins over an explicitminFractionDigits).formatAmount/CurrencyStyle) is intentionally not changed — it routes through the platform formatters, and adding the flag there would split one method across two engines.Why not
minFractionDigits?Setting
min=0would turn34.20into34.2(strips the trailing zero). This flag is all-or-nothing: drop all fraction digits or keep the currency's full count.kurrency-deci
Adds
CurrencyFormatter.formatWithOptions(amount: Deci, …)overloads (currency code +Kurrency), closing the prior gap where Deci users had no options access — and giving an exact, decimal-native input.Testing
Extensive
commonTestcoverage (runs on JVM/JS/WasmJs/iOS): all-zero dropped, non-zero kept, partial trailing zero, grouping preserved, round-down-to-zero, round-up-to-non-zero, zero amount, negatives, 3-digit currency (BHD), comma-decimal locale (German), JPY no-op, hide-wins-over-min, the high-levelKurrency.formatAmountWithOptionsentry, serialization round-trip + absent-field default, and Deci (code +Kurrency+ high-precision). All green on every platform.Backward-compatible: new
@Serializablefield defaults tofalse.