You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[$250] Split - First split percentage changes when the second split percentage is changed #78098
BugSomething is broken. Auto assigns a BugZero manager.EngineeringExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributorsWeeklyKSv2
Version Number: 9.2.82-0 Reproducible in staging?: Yes Reproducible in production?: N/A - new feature, doesn't exist in prod If this was caught during regression testing, add the test name, ID and link from BrowserStack:#74652 Email or phone of affected tester (no customers):applausetester+khdjdjdjsjsk@applause.expensifail.com Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: Mac 26.1 / Chrome App Component: Money Requests
Action Performed:
Go to staging.new.expensify.com
Go to workspace chat.
Create an expense of amount 12.00.
Open the expense report.
Click More > Split.
Go to Percent.
Enter 50.2% for the first split.
On the second split, enter 49.8%.
Remove 8 from the second split so that it becomes 49.
Expected Result:
The first split percentage will not change.
Actual Result:
The first split percentage changes to 50.1% when the second split is changed to 49.
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
Identify the pull request that introduced this issue and revert it.
Please re-state the problem that we are trying to solve in this issue.
When editing a split under the "Percentages" tab, changing one split's percentage (for example, 49.8 → 49.7) can unexpectedly change a different already-set split by 0.1% (for example, 50.2 → 50.1). This is surprising to users and harms the editing experience.
What is the root cause of that problem?
Editing a percentage immediately converts the percentage into backend cents (using Math.round) and writes the amount to Onyx.
The UI recomputes displayed percentages from the stored cents using a function that:
Floors each percentage to 0.1,
Computes the floored sum, subtracts from 100 to get a remainder,
Adds the remainder to the row with the maximum amount.
Small cent-level changes caused by the percent → cent conversion can change floored percentages, the remainder, or which row is considered the max, so another row's displayed percentage can change by 0.1 even though the user only edited a different row.
Example reproduced:
Total = 335¢ ($3.35)
Before change: amounts = [168, 167] → displayed percentages [50.2, 49.8]
Edit second split 49.8 → 49.7: amounts = [168, 166] → displayed percentages [50.1, 49.5]
First split changed 50.2 → 50.1 even though it wasn't edited.
The offending code is in src/libs/IOUUtils.ts
/**
* Calculate a split amount in backend cents from a percentage of the original amount.
*/
function calculateSplitAmountFromPercentage(totalInCents: number, percentage: number): number {
const totalAbs = Math.abs(totalInCents);
// Clamp percentage to [0, 100] without rounding to preserve decimal precision
const clamped = Math.min(100, Math.max(0, percentage));
// Rounding to the nearest cent here is the source of the 0.1% fluctuation
const amount = Math.round((totalAbs * clamped) / 100);
if (amount === 0) {
return 0;
}
return totalInCents < 0 ? -amount : amount;
}
/**
* Recomputing displayed percentages (floors + remainder assignment)
*/
const flooredPercentages = amountsAbs.map((amount) => floorToOneDecimal((amount / totalAbs) * 100));
const sumOfFlooredPercentages = roundToOneDecimal(
flooredPercentages.reduce((sum, current) => sum + current, 0),
);
const remainder = roundToOneDecimal(100 - sumOfFlooredPercentages);
// ... (logic to find lastMaxIndex)
adjustedPercentages[lastMaxIndex] = roundToOneDecimal((adjustedPercentages.at(lastMaxIndex) ?? 0) + remainder);
The edit flow updates Onyx immediately in src/pages/iou/SplitExpensePage.tsx:
What changes do you think we should make in order to solve the problem?
Preserve the user's draft while they edit a percentage and do not immediately persist to Onyx (do not convert to cents until the user finishes editing).
This prevents transient cent rounding changes from affecting other rows' displayed percentages while the user is actively editing.
Implementation detail: stop calling the global update on every keystroke; only update local percentageDraft on input change and call onSplitExpenseValueChange (persist) on blur / commit.
Current behavior (calling update on every input change):
// src/components/SelectionListWithSections/SplitExpense/SplitPercentageInput.tsx
<PercentageForm
onInputChange={(value) => {
setPercentageDraft(value);
// TODO: Remove this call to avoid volatile re-balancing on every keystroke
onSplitExpenseValueChange(value);
}}
onBlur={(event) => {
setPercentageDraft(undefined);
if (onInputBlur) {
onInputBlur(event);
}
}}
/>
Proposed change (only set draft on input change; persist on blur):
<PercentageForm
onInputChange={(value) => {
// Only update the local draft while editing to prevent volatile re-balancing
setPercentageDraft(value);
}}
onBlur={(event) => {
// When editing ends, persist the final value to Onyx
const finalValue = percentageDraft ?? String(splitItem.percentage ?? 0);
setPercentageDraft(undefined);
if (onInputBlur) {
onInputBlur(event);
}
// Persist once on blur/commit to ensure stable display for other splits
onSplitExpenseValueChange(finalValue);
}}
/>
Why this is good:
Keeps the existing server/cent rounding behaviour untouched (no backward-incompatible rounding changes).
Fixes the main UX problem: the user won't see other rows change during their edit.
While the user is editing the second row, the first row's displayed percentage remains stable.
After blur/commit, final displayed percentages match the existing business logic.
Optional follow-up: We can revisit calculateSplitPercentagesFromAmounts to explore more deterministic remainder assignment if we want to eliminate all edge cases. This is a medium-risk change and should be considered only after tests and UX-first fix.
What alternative solutions did you explore? (Optional)
Change rounding strategy (e.g., round-to-nearest 0.1 instead of floor + remainder). This could alter guarantees like "equal amounts ALWAYS have equal percentages" and affect backward compatibility.
Assign remainder deterministically to a fixed index (e.g., first max or edited row) rather than the last max. This would reduce flipping but is a behaviour change and needs careful review.
Avoid converting percentages to cents until final save (store raw percentages in draft stores). This requires larger data-flow changes and more tests.
@twisterdotcom@ShridharGoel@mountiny this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
BugSomething is broken. Auto assigns a BugZero manager.EngineeringExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributorsWeeklyKSv2
Activity
melvin-bot commentedon Dec 19, 2025
Triggered auto assignment to @twisterdotcom (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.melvin-bot commentedon Dec 19, 2025
Triggered auto assignment to @srikarparsi (
DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.melvin-bot commentedon Dec 19, 2025
💬 A slack conversation has been started in #expensify-open-source
github-actions commentedon Dec 19, 2025
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
twisterdotcom commentedon Dec 19, 2025
This is not a blocker surely. This is so edge case. We have to round somewhere, somehow.
twisterdotcom commentedon Dec 19, 2025
@srikarparsi can override me, but I am calling this not a blocker.
twisterdotcom commentedon Dec 19, 2025
Let's see if anybody has any nice ideas about avoiding the confusion somehow, but this is a weekly bug at best.
25 remaining items
ShridharGoel commentedon Dec 30, 2025
#78098 (comment)
🎀 👀 🎀 C+ reviewed
melvin-bot commentedon Dec 30, 2025
Triggered auto assignment to @mountiny, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
mountiny commentedon Dec 30, 2025
Discussing here
beodw commentedon Dec 31, 2025
Proposal
Please re-state the problem that we are trying to solve in this issue.
When editing a split under the "Percentages" tab, changing one split's percentage (for example, 49.8 → 49.7) can unexpectedly change a different already-set split by 0.1% (for example, 50.2 → 50.1). This is surprising to users and harms the editing experience.
What is the root cause of that problem?
Editing a percentage immediately converts the percentage into backend cents (using Math.round) and writes the amount to Onyx.
The UI recomputes displayed percentages from the stored cents using a function that:
Small cent-level changes caused by the percent → cent conversion can change floored percentages, the remainder, or which row is considered the max, so another row's displayed percentage can change by 0.1 even though the user only edited a different row.
Example reproduced:
Total = 335¢ ($3.35)
Before change: amounts = [168, 167] → displayed percentages [50.2, 49.8]
Edit second split 49.8 → 49.7: amounts = [168, 166] → displayed percentages [50.1, 49.5]
First split changed 50.2 → 50.1 even though it wasn't edited.
The offending code is in src/libs/IOUUtils.ts
The edit flow updates Onyx immediately in src/pages/iou/SplitExpensePage.tsx:
What changes do you think we should make in order to solve the problem?
Preserve the user's draft while they edit a percentage and do not immediately persist to Onyx (do not convert to cents until the user finishes editing).
This prevents transient cent rounding changes from affecting other rows' displayed percentages while the user is actively editing.
Implementation detail: stop calling the global update on every keystroke; only update local percentageDraft on input change and call onSplitExpenseValueChange (persist) on blur / commit.
Current behavior (calling update on every input change):
Proposed change (only set draft on input change; persist on blur):
Why this is good:
Optional follow-up: We can revisit calculateSplitPercentagesFromAmounts to explore more deterministic remainder assignment if we want to eliminate all edge cases. This is a medium-risk change and should be considered only after tests and UX-first fix.
What alternative solutions did you explore? (Optional)
Change rounding strategy (e.g., round-to-nearest 0.1 instead of floor + remainder). This could alter guarantees like "equal amounts ALWAYS have equal percentages" and affect backward compatibility.
Assign remainder deterministically to a fixed index (e.g., first max or edited row) rather than the last max. This would reduce flipping but is a behaviour change and needs careful review.
Avoid converting percentages to cents until final save (store raw percentages in draft stores). This requires larger data-flow changes and more tests.
melvin-bot commentedon Jan 2, 2026
@twisterdotcom @ShridharGoel @mountiny this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
mountiny commentedon Jan 2, 2026
Awaiting discussion output here https://expensify.slack.com/archives/C01GTK53T8Q/p1767098161950269
mountiny commentedon Jan 5, 2026
We might want to handle this as part of #70799
ShridharGoel commentedon Jan 6, 2026
@mountiny Thanks for the update, do you think I can get assigned there as C+ if we plan to close this one?
mountiny commentedon Jan 6, 2026
Going to do that, thanks