-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HOLD for payment 2024-07-26][$500] When amending the amount, if the last digit is a 0, we don't show it. #34894
Comments
Job added to Upwork: https://www.upwork.com/jobs/~0178a9407eab9689fe |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @eVoloshchak ( |
This looks like a pretty normal behavior for decimals, isn't that expected?🤔 |
ProposalPlease re-state the problem that we are trying to solve in this issue.if the last digit is a 0 in amount we dont show it What is the root cause of that problem?in this function whe dividing over 100 the last digit is removed if its 0 Lines 91 to 93 in 82b76c1
What changes do you think we should make in order to solve the problem?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. |
ProposalPlease re-state the problem that we are trying to solve in this issue.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 What is the root cause of that problem?in this function when dividing over 100 the last digit is removed if its 0 Lines 91 to 93 in 82b76c1
in the above function trailing 0 is getting truncated which is the root cause of the problem What changes do you think we should make in order to solve 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));
} What alternative solutions did you explore? (Optional) |
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! 📣
|
ProposalPlease 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. Lines 91 to 93 in 82b76c1
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.
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 : |
Triggered auto assignment to @sakluger ( |
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 |
I agree with @twisterdotcom, this doesn't look consistent @abzokhattab, I think this is the best proposal so far, but it has one problem - it changes the return type of @cjoshi-zeals, your proposal doesn't work for me, could you double-check it please?
We should display Screen.Recording.2024-01-24.at.23.57.22.mov@Aditya-svg-code, your proposal also doesn't work for me, could you double-check? |
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 |
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));
} |
@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 This is the function which will return string for the bill purpose.
This is the function which will return number for the furthur calculation.
in |
I agree with @twisterdotcom - dollar amounts should always be reflected with two decimals. |
ProposalPlease re-state the problem that we are trying to solve in this issue.When amending the amount, if the last digit is a 0, it isn't displayed What is the root cause of that problem?In App/src/pages/iou/steps/MoneyRequestAmountForm.js Lines 121 to 122 in 0d0b0a8
But here as we pass a numerical value, anything of the format What changes do you think we should make in order to solve the problem?Instead of updating the const initializeAmount = useCallback((newAmount) => {
const frontendAmount = newAmount ?
(newAmount.includes('.') ? parseFloat(CurrencyUtils.convertToFrontendAmount(newAmount)).toFixed(2) : CurrencyUtils.convertToFrontendAmount(newAmount))
: ''; Result:Screencast.from.01-26-2024.12.22.18.AM.webmWhat alternative solutions did you explore? (Optional)N/A |
@eVoloshchak , By taking into consideration your comments on above proposals, i have proposed a different solution which doesn't have to deal with the |
The PR is still not merged. |
PR in review! Hopefully should get merged today |
we're merged! |
No automation for some reason, but this has been merged and deployed. Should be ready for payment on 7/26 |
Thanks @dangrous 👍 - I updated the title accordingly and will come back tomorrow to make payments. |
Summarizing payment on this issue: Contributor: @abzokhattab $500, paid via Upwork |
@eVoloshchak can you please complete the BZ checklist? |
Bump @eVoloshchak |
Regression Test Proposal
Do we agree 👍 or 👎 |
Thanks! |
$500 approved for @eVoloshchak |
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
0.gets.ignored.mp4
View all open jobs on GitHub
Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @eVoloshchakThe text was updated successfully, but these errors were encountered: