-
Notifications
You must be signed in to change notification settings - Fork 34
[-]:feat/checkout little improves #1963
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
Changes from 1 commit
8283456
d0ef7a4
f309b3d
81a7846
516220a
86ef365
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,14 +21,18 @@ describe('Formatting the price to have 2 decimals', () => { | |
| }); | ||
|
|
||
| describe('The price has more than 2 decimals', () => { | ||
| it('When the price has more than 2 decimals, then the function returns the price with 2 decimals (truncated with high precision, 10.456 -> 10.45 - 10.001 -> 10 - 1.999 -> 1.99)', () => { | ||
| expect(formatPrice(10.456)).toBe('10.45'); | ||
| it('When the price has more than 2 decimals, then the function returns the price rounded to 2 decimals (10.456 -> 10.46 - 10.001 -> 10 - 1.999 -> 2)', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use test instead. |
||
| expect(formatPrice(10.456)).toBe('10.46'); | ||
| expect(formatPrice(10.001)).toBe('10'); | ||
| expect(formatPrice(1.999)).toBe('1.99'); | ||
| expect(formatPrice(1.999)).toBe('2'); | ||
| }); | ||
| }); | ||
|
|
||
| it('Handles edge case where value is nearly integer due to float error', () => { | ||
| expect(formatPrice(10.0000001)).toBe('10'); | ||
| }); | ||
|
|
||
| it('Handles floating point precision error (19.99 * 100 = 1998.999... in JS)', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use when..., then...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and change it from "it" to "test". the "it" tests are like: it('should do .... when doing ....') |
||
| expect(formatPrice(19.99)).toBe('19.99'); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| export const formatPrice = (price: number) => { | ||
| const truncated = Math.floor(Number(price.toFixed(8)) * 100) / 100; | ||
| const truncated = Math.round(Number(price.toFixed(8)) * 100) / 100; | ||
| const formatted = truncated.toFixed(2); | ||
| return formatted.endsWith('.00') ? String(truncated) : formatted; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the text for all languages.