Closed kavimuru closed 3 months ago
Job added to Upwork: https://www.upwork.com/jobs/~0178a9407eab9689fe
Triggered auto assignment to Contributor-plus team member for initial proposal review - @eVoloshchak (External
)
This looks like a pretty normal behavior for decimals, isn't that expected?π€
if the last digit is a 0 in amount we dont show it
in this function whe dividing over 100 the last digit is removed if its 0 https://github.com/Expensify/App/blob/82b76c1a36cf1a01b00c14510a5812a591e7f2fd/src/libs/CurrencyUtils.ts#L91-L93
we can force it to always return two decimal digits after the comma since the max allowed numbers of digits after the comma is two:
function convertToFrontendAmount(amountAsInt: number): string {
const amount = Math.trunc(amountAsInt) / 100.0;
return amount.toFixed(2);
}
Or we can just check if the last digit is not then return the amount as in the old calculations but i would prefer not to have edge cases.
If the trailing digit is 0 then it is getting truncated. Show 0 digits upto 2 decimals for amounts having significant number after the decimal
in this function when dividing over 100 the last digit is removed if its 0 https://github.com/Expensify/App/blob/82b76c1a36cf1a01b00c14510a5812a591e7f2fd/src/libs/CurrencyUtils.ts#L91-L93
in the above function trailing 0 is getting truncated which is the root cause of the problem ``
We can make changes in the code such it will keep the trailing zero in case there is any significant digit after decimal and not in case it is a whole number which will be the edge case scenario.
So based on the bug if it is 23.10 it should display the same in amount input without truncating.
and also in my solution for eg. 24.00 will be shown as 24 since trailing zeros after decimals don't have any significant digits.
keep the definition of the function intact without changing its return type.
function convertToFrontendAmount(amountAsInt: number): number {
// Convert the input integer to a floating-point number by dividing it by 100.0
const amount = Math.trunc(amountAsInt) / 100.0;
// Check if the decimal part is zero, then remove it
if (amount % 1 === 0) {
return amount;
}
// Return the resulting floating-point number
return Number(amount.toFixed(2));
}
I agree with @paultsimura and @cjoshi-zeals, thinking of UX, it would also help users to change the value more conveniently as compared to having to cancel the 0 and input a digit again :)
π£ @Aditya-svg-code! π£ Hey, it seems we donβt have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
Please re-state the problem that we are trying to solve in this issue.
when dividing the number by 100.0 it's unable to display the 0 after the decimal.
What is the root cause of that problem?
in this function when dividing over 100.0 the unit digit is removed if it is 0. for eg. if amountAsInt = 2370 then 2370/100.0 = 23.7 but we want 23.70
Lines 91 to 93 in 82b76c1
function convertToFrontendAmount(amountAsInt: number): number {
return Math.trunc(amountAsInt) / 100.0;
}
What changes do you think we should make to solve the problem?
When you perform a division operation, the result is often displayed with the minimum required precision. To format the result with a specific number of decimal places, you can use the toFixed() method.
toFixed() method returns a string, so if you need to perform further calculations, you may need to convert it back to a number using parseFloat(). Here's how you can fix the issue.
function convertToFrontendAmount(amountAsInt: number): number {
const result = Math.trunc(amountAsInt) / 100.0;
return parseFloat(result.toFixed(2));
}
Additionally, if amountAsInt = 2300 then the previous function was providing the result as 23.0 only, but in my solution it will return 23.00 as the result, usually in bills we should show the numbers after the decimal point even if it is 0, it helps the customer understand the visibility of the payment.
Contributor details : Expensify account email: soni96996@gmail.com Upwork Profile Link: https://www.upwork.com/freelancers/~015162f5f4b61238ea
Triggered auto assignment to @sakluger (Bug
), see https://stackoverflow.com/c/expensify/questions/14418 for more details.
So, this was reported by me (which is why I added the label instead of taking it on), but I disagree that we shouldn't show the last 0
. I agree 12.30
is the same as 12.3
, but I found it odd that we didn't show the last character. If you asked your mate or your company to send you $12.30, you wouldn't ask them to send you $12.3.
I agree with @twisterdotcom, this doesn't look consistent https://github.com/Expensify/App/assets/9059945/00e62fe4-c2b1-492e-9c34-d2495b486bb2 Banking apps also do this, if you put 12.3 it will still be displayed as 12.30 on the next step
@abzokhattab, I think this is the best proposal so far, but it has one problem - it changes the return type of convertToFrontendAmount
from number
to string
. We need it to be number to calculate isTaxAmountInvalid
@cjoshi-zeals, your proposal doesn't work for me, could you double-check it please?
and also in my solution for eg. 24.00 will be shown as 24 since trailing zeros after decimals don't have any significant digits
We should display 24.00
in this case. 24 is displayed as 24.00 on the previous screen, those two should be identical
https://github.com/Expensify/App/assets/9059945/faedb657-a3cf-4fa0-8167-985d9d4b5037
@Aditya-svg-code, your proposal also doesn't work for me, could you double-check?
@abzokhattab, I think this is the best https://github.com/Expensify/App/issues/34894#issuecomment-1904253989 so far, but it has one problem - it changes the return type of convertToFrontendAmount from number to string. We need it to be number to calculate isTaxAmountInvalid
converting the output to a number will remove the leading zeros, thus we can handle this case ( isTaxAmountInvalid individually by converting it into a number
we can do that by making the following two functions:
function convertToFrontendAmountAsString(amountAsInt: number): string {
return convertToFrontendAmount(number).toFixed(2);
}
function convertToFrontendAmount(amountAsInt: number): number {
return Math.trunc(amountAsInt) / 100.0;
}
then in the isTaxAmountInvalid
we need to use the convertToFrontendAmount
method and in other occurrences we can use the other method
We should display 24.00 in this case. 24 is displayed as 24.00 on the previous screen, those two should be identical
@eVoloshchak
In that case, we just need to remove the condition for checking if there is no significant digit after the decimal, here is my updated solution
in the below solution will keep the return type of the function the same and will also deliver the desired output.
function convertToFrontendAmount(amountAsInt: number): number {
// Convert the input integer to a floating-point number by dividing it by 100.0
const amount = Math.trunc(amountAsInt) / 100.0;
// Return the resulting floating-point number
return Number(amount.toFixed(2));
}
I agree with @twisterdotcom, this doesn't look consistent https://github.com/Expensify/App/assets/9059945/00e62fe4-c2b1-492e-9c34-d2495b486bb2 Banking apps also do this, if you put 12.3 it will still be displayed as 12.30 on the next step
@abzokhattab, I think this is the best proposal so far, but it has one problem - it changes the return type of
convertToFrontendAmount
fromnumber
tostring
. We need it to be number to calculate isTaxAmountInvalid@cjoshi-zeals, your proposal doesn't work for me, could you double-check it please?
and also in my solution for eg. 24.00 will be shown as 24 since trailing zeros after decimals don't have any significant digits
We should display
24.00
in this case. 24 is displayed as 24.00 on the previous screen, those two should be identicalScreen.Recording.2024-01-24.at.23.57.22.mov @Aditya-svg-code, your proposal also doesn't work for me, could you double-check?
@eVoloshchak I have double checked my solution and the issue is that converting it to the number and the leading zero after decimal is getting removed but if we keep it string then it is working correctly, and for the further calculation we will create a function convertToFrontendAmountAsNumber()
that return a number for the calculation.
This is the function which will return string for the bill purpose.
function convertToFrontendAmount(amountAsInt: number): string {
const result = Math.trunc(amountAsInt) / 100.0;
return (result.toFixed(2)); //return the value of result as string
}
This is the function which will return number for the furthur calculation.
function convertToFrontendAmountAsNumber(amountAsInt: number): number {
return Math.trunc(amountAsInt) / 100.0;
}
in isTaxAmountInvalid
we need to use convertToFrontendAmountAsNumber()
to get a number for calculation.
I agree with @twisterdotcom - dollar amounts should always be reflected with two decimals.
When amending the amount, if the last digit is a 0, it isn't displayed
In initializeAmount
, we pass the variable newAmount
to the function convertToFrontendAmount
But here as we pass a numerical value, anything of the format 9.70, 9.700, 9.7000
will be considered as 9.7
by default by javascript variables:
Instead of updating the currencyUtil
, i propose that we update initializeAmount
to fix the amount to 2 decimal places by using toFixed(2)
as shown below:
const initializeAmount = useCallback((newAmount) => {
const frontendAmount = newAmount ?
(newAmount.includes('.') ? parseFloat(CurrencyUtils.convertToFrontendAmount(newAmount)).toFixed(2) : CurrencyUtils.convertToFrontendAmount(newAmount))
: '';
Screencast from 01-26-2024 12:22:18 AM.webm
N/A
@abzokhattab, I think this is the best https://github.com/Expensify/App/issues/34894#issuecomment-1904253989 so far, but it has one problem - it changes the return type of convertToFrontendAmount from number to string. We need it to be number to calculate isTaxAmountInvalid
@eVoloshchak , By taking into consideration your comments on above proposals, i have proposed a different solution which doesn't have to deal with the CurrencyUtils
, looking forward to your review :)
Instead of updating the currencyUtil, i propose that we update initializeAmount to fix the amount to 2 decimal places by using toFixed(2) as shown below:
@RohanSasne, this adds a small regression, amount is altered (formatted) when you're navigated to the next screen:
https://github.com/Expensify/App/assets/9059945/f1a66571-f02f-4f90-8b02-b193d7c49503
I think we should proceed with @abzokhattab's updated proposal
There's only a single occurrence when we need amount to have a number
type, moving it into a separate function is simple and reliable
πππ C+ reviewed!
Triggered auto assignment to @dangrous, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
@RohanSasne, this adds a small regression, amount is altered (formatted) when you're navigated to the next screen: So, this was reported by me (which is why I added the label instead of taking it on), but I disagree that we shouldn't show the last 0. I agree 12.30 is the same as 12.3, but I found it odd that we didn't show the last character. If you asked your mate or your company to send you $12.30, you wouldn't ask them to send you $12.3.
Hey @eVoloshchak just a small doubt , i guess by the comments from @twisterdotcom , this is what is intended !? in banking transactions, we take $12 dollars as $12.00 :thinking: , so won't it be appropriate to have it here too ?
In the screen recording you attached, there too we display it as 23.00:
Currently also on staging, you can see that when we enter value as 23 it is displayed as 23.00 (which is intended) :) so won't my proposal be a more optimal
fix for this bug?
π£ It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? πΈ
Yeah I think @abzokhattab's is probably the clearest moving forward. @RohanSasne you're not wrong here, it's not quite consistent, but I think if the user has JUST entered a value, we'd want to maintain it as is, making it easier for the user to fix if needed. (@sakluger or @twisterdotcom let me know if you disagree). This is also how Square Cash and Venmo do it, as a reference.
Two notes:
CurrencyUtilsTest
amount ? CurrencyUtils.convertToFrontendAmount(amount).toString() : ''
line that's used, though I defer to your judgement on that.π£ @abzokhattab π An offer has been automatically sent to your Upwork account for the Contributor role π Thanks for contributing to the Expensify app!
Offer link Upwork job Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review π§βπ» Keep in mind: Code of Conduct | Contributing π
Hi @abzokhattab, how is the PR coming?
Working on it β¦ thanks
hey @eVoloshchak @abzokhattab how are we looking? Seems like there's one bug we still need to fix, and then some merge conflicts. Can we get this ready for final review / merging by Monday or Tuesday? Thank you!
Bumping this when you can, can we get this updated and rereviewed on Monday please? Thanks!
Sorry for the delay .. working on the latest comments today
How are we looking on this @abzokhattab ? Can we get it reviewed today, do you think?
I covered the last requested requirement and its still pending on the review
This issue has not been updated in over 15 days. @dangrous, @sakluger, @eVoloshchak, @abzokhattab eroding to Monthly issue.
P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!
β οΈ Looks like this issue was linked to a Deploy Blocker here
If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.
If a regression has occurred and you are the assigned CM follow the instructions here.
If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.
Had to revert the PR due to https://github.com/Expensify/App/issues/39599
@abzokhattab, this bug was caused by a conflict when merging main, the commit at fault is https://github.com/Expensify/App/commit/bd6868207f1e8e03899515721ed6899eb50cf172
β οΈ Looks like this issue was linked to a Deploy Blocker here
If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.
If a regression has occurred and you are the assigned CM follow the instructions here.
If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.
Hrm okay let's see if we can figure out a new way forward that doesn't cause that blocker (or https://github.com/Expensify/App/issues/39537)
I updated the condition in my proposal a little now and this can fix the issue without updating any utility function imo:
const initializeAmount = useCallback((newAmount) => {
const frontendAmount = newAmount ?
(newAmount.includes('.') ? parseFloat(CurrencyUtils.convertToFrontendAmount(newAmount)).toFixed(2) : CurrencyUtils.convertToFrontendAmount(newAmount))
: '';
Also regression pointed by @eVoloshchak would also be fixed here, @abzokhattab can you try with this please
I will be providing a PR today. thanks
Reviewing
label has been removed, please complete the "BugZero Checklist".
The solution for this issue has been :rocket: deployed to production :rocket: in version 1.4.60-13 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:
If no regressions arise, payment will be issued on 2024-04-15. :confetti_ball:
For reference, here are some details about the assignees on this issue:
BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:
How are we looking on the updated fix for this? Thanks!
working on a fix, thanks for the ping
the PR is ready https://github.com/Expensify/App/pull/40062 please let me know if you have any other comments!
I removed the payment hold since the original PR caused a regression and we now have a new PR (https://github.com/Expensify/App/pull/40062) in review.
On that new PR, there is no BE reviewer. @eVoloshchak @dangrous is that correct?
I'm also going to throw this in wave-collect. It could possibly be vsb, but I think collect is more appropriate.
@dangrous, @sakluger, @eVoloshchak, @abzokhattab Whoops! This issue is 2 days overdue. Let's get this updated quick!
@dangrous, @sakluger, @eVoloshchak, @abzokhattab Eep! 4 days overdue now. Issues have feelings too...
If you havenβt already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
Version Number: 1.4.29-0 Reproducible in staging?: y Reproducible in production?: y If this was caught during regression testing, add the test name, ID and link from TestRail: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @twisterdotcom Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1705662590072039
Action Performed:
Expected Result:
Should see 0 at the end
Actual Result:
"0" is missing
Workaround:
Platforms:
Which of our officially supported platforms is this issue occurring on?
Screenshots/Videos
Add any screenshot/video evidence
https://github.com/Expensify/App/assets/43996225/9bb584e7-49a7-4968-ab33-db9e71b281f8
View all open jobs on GitHub
Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @eVoloshchak