Skip to content

fix(transfer-intrabank): correct floating-point truncation in amount display - #2034

Open
bhuvan-somisetty wants to merge 2 commits into
openMF:devfrom
bhuvan-somisetty:fix/amount-display-precision-intrabank
Open

fix(transfer-intrabank): correct floating-point truncation in amount display#2034
bhuvan-somisetty wants to merge 2 commits into
openMF:devfrom
bhuvan-somisetty:fix/amount-display-precision-intrabank

Conversation

@bhuvan-somisetty

@bhuvan-somisetty bhuvan-somisetty commented May 14, 2026

Copy link
Copy Markdown

The recent payee card shows the last amount you sent to a beneficiary — and for a lot of common amounts, it was showing the wrong value. ₹5.99 appears as ₹5.98. ₹99.99 appears as ₹99.98. ₹10.30 appears as ₹10.29. In a payments app, seeing a different amount than what you actually sent is genuinely alarming.

The root cause is a classic floating-point pitfall. The old code computed the decimal part like this:

val wholePart = amount.toLong()
val decimalPart = ((amount - wholePart) * 100).toInt()

The problem: 5.99 - 5 in floating-point is not 0.99 — it's 0.9899999999999999. Multiply that by 100 and you get 98.99.... Calling .toInt() truncates toward zero, so you get 98 instead of 99. The display shows 5.98.

This affects any amount where the decimal part has a negative epsilon in its binary representation, which includes most .x9 endings and many others. It's unpredictable from the user's perspective, which makes it feel like data corruption.

The fix avoids floating-point subtraction entirely. Instead of splitting the number and computing the decimal part through subtraction, we multiply the whole amount by 100, round to the nearest integer, and then use integer division and modulo:

val cents = (amount * 100).roundToInt()
val wholePart = cents / 100
val decimalPart = cents % 100

Multiplying first keeps the rounding error small enough that roundToInt() always lands on the correct cent value.

Amount Before After
5.99 5.98 5.99
99.99 99.98 99.99
10.30 10.29 10.30
63,823.00 63,823.00 63,823.00

Verified by tracing through the arithmetic manually for the failing cases and confirming the fixed output matches the expected display.

Summary by CodeRabbit

  • Bug Fixes
    • Improved how transfer amounts are rounded and displayed in the recent payee card.
    • Amounts now show more consistent two-decimal formatting, reducing edge cases where values could appear slightly off due to rounding.

@bhuvan-somisetty
bhuvan-somisetty requested a review from a team May 14, 2026 16:11
@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@bhuvan-somisetty, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f318d00c-0fb9-488d-8714-71e92a5a61e2

📥 Commits

Reviewing files that changed from the base of the PR and between 8540194 and 1d3e1db.

📒 Files selected for processing (1)
  • feature/transfer-intrabank/src/commonMain/kotlin/org/mifospay/feature/transfer/intrabank/hub/components/RecentPayeeCard.kt
📝 Walkthrough

Walkthrough

The formatAmount function in RecentPayeeCard.kt is updated to compute cents by rounding the amount multiplied by 100, then deriving the whole and decimal parts from that rounded value, replacing the prior truncation-based derivation.

Changes

Amount Formatting Precision

Layer / File(s) Summary
Cent-based amount formatting
feature/transfer-intrabank/.../RecentPayeeCard.kt
Imports kotlin.math.roundToInt and refactors formatAmount to round the amount to cents before deriving whole and decimal parts, replacing the previous truncation-based logic.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Suggested reviewers: therajanmaurya

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: correcting amount display truncation in intrabank transfer payees.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
feature/transfer-intrabank/src/commonMain/kotlin/org/mifospay/feature/transfer/intrabank/hub/components/RecentPayeeCard.kt (1)

128-139: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Rounding fix correctly addresses the truncation bug.

The cent-based rounding via roundToInt() correctly resolves the ₹5.99/₹99.99/₹10.30 display issue described in the PR objective, since it rounds before splitting rather than truncating a raw double subtraction.

One minor note: cents is derived from amount * 100 as an Int, which overflows above ~21.4 million currency units. Given this is a recent-payee transfer amount, this is unlikely in practice, but using roundToLong() would remove the ceiling entirely at negligible cost.

♻️ Optional hardening
-    val cents = (amount * 100).roundToInt()
-    val wholePart = cents / 100
-    val decimalPart = cents % 100
+    val cents = (amount * 100).roundToLong()
+    val wholePart = cents / 100
+    val decimalPart = cents % 100
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@feature/transfer-intrabank/src/commonMain/kotlin/org/mifospay/feature/transfer/intrabank/hub/components/RecentPayeeCard.kt`
around lines 128 - 139, The amount formatting in formatAmount currently uses
roundToInt() into an Int, which can overflow for very large transfer values.
Update the cents calculation to use a wider integer type in
RecentPayeeCard.formatAmount so the rounding fix remains safe for large amounts,
while keeping the same whole-part/decimal-part formatting behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@feature/transfer-intrabank/src/commonMain/kotlin/org/mifospay/feature/transfer/intrabank/hub/components/RecentPayeeCard.kt`:
- Around line 128-139: The amount formatting in formatAmount currently uses
roundToInt() into an Int, which can overflow for very large transfer values.
Update the cents calculation to use a wider integer type in
RecentPayeeCard.formatAmount so the rounding fix remains safe for large amounts,
while keeping the same whole-part/decimal-part formatting behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3229857e-c9ca-4827-bd28-bf87a04d16eb

📥 Commits

Reviewing files that changed from the base of the PR and between 78d468b and 8540194.

📒 Files selected for processing (1)
  • feature/transfer-intrabank/src/commonMain/kotlin/org/mifospay/feature/transfer/intrabank/hub/components/RecentPayeeCard.kt

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix/amount-display-precision-intrabank branch from 8540194 to 1d3e1db Compare July 5, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant