-
Notifications
You must be signed in to change notification settings - Fork 5
Format amount in Orders #1091
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
Open
zaelgohary
wants to merge
3
commits into
development
Choose a base branch
from
development_fix_small_amount
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Format amount in Orders #1091
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
b2434ce
Create formatSmallAmount and use it in total amount & amount in order…
zaelgohary ba691b4
Fix trailling zeros in amounts, Add thousand seperator, update forma…
zaelgohary 0171e00
Replace thousand seperator func w NumberFormat, refactor formatAmount…
zaelgohary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:threebotlogin/helpers/transaction_helpers.dart'; | ||
|
||
void main() { | ||
group('formatAmountDisplay', () { | ||
test('handles large amounts (user-friendly)', () { | ||
expect(formatAmountDisplay('1234.567890'), equals('1,234.57')); // 2 decimals + thousand separators | ||
expect(formatAmountDisplay('5000.00'), equals('5,000')); // Remove trailing zeros + separators | ||
expect(formatAmountDisplay('10000.123'), equals('10,000.12')); // 2 decimals max + separators | ||
expect(formatAmountDisplay('1000000.00'), equals('1,000,000')); // Large numbers with separators | ||
}); | ||
|
||
test('handles medium amounts (user-friendly)', () { | ||
expect(formatAmountDisplay('123.456789'), equals('123.457')); // 3 decimals for medium amounts | ||
expect(formatAmountDisplay('1.50'), equals('1.5')); // Remove trailing zeros | ||
expect(formatAmountDisplay('99.999'), equals('99.999')); // Keep significant decimals | ||
}); | ||
|
||
test('handles small amounts (user-friendly)', () { | ||
expect(formatAmountDisplay('0.12345678'), equals('0.1235')); // 4 decimals for small amounts | ||
expect(formatAmountDisplay('0.1000'), equals('0.1')); // Remove trailing zeros | ||
}); | ||
|
||
test('handles very small amounts with approximation', () { | ||
expect(formatAmountDisplay('0.00670241'), equals('~0.0067')); // Approximated with ~ symbol | ||
expect(formatAmountDisplay('0.001234567'), equals('~0.0012')); // Approximated with ~ symbol | ||
expect(formatAmountDisplay('0.0005'), equals('0.0005')); // Keep as-is if short enough | ||
expect(formatAmountDisplay('0.000100'), equals('0.0001')); // Remove trailing zeros | ||
}); | ||
|
||
test('handles tiny amounts with approximation', () { | ||
expect(formatAmountDisplay('0.000012345678'), equals('~0.000012')); // Approximate tiny amounts | ||
expect(formatAmountDisplay('0.00000123456789'), equals('~0.0000012')); // Show 2 significant digits | ||
expect(formatAmountDisplay('0.00000006'), equals('0.00000006')); // Keep if short enough | ||
}); | ||
|
||
test('handles whole numbers', () { | ||
expect(formatAmountDisplay('5'), equals('5')); | ||
expect(formatAmountDisplay('100'), equals('100')); | ||
expect(formatAmountDisplay('1000'), equals('1,000')); // Thousand separator added | ||
}); | ||
|
||
test('handles edge cases', () { | ||
expect(formatAmountDisplay('0'), equals('0')); | ||
expect(formatAmountDisplay('0.0'), equals('0')); | ||
expect(formatAmountDisplay('0.00'), equals('0')); | ||
}); | ||
|
||
test('removes trailing zeros consistently', () { | ||
expect(formatAmountDisplay('1.50000000'), equals('1.5')); | ||
expect(formatAmountDisplay('0.12345600'), equals('0.1235')); | ||
expect(formatAmountDisplay('1000.00'), equals('1,000')); // Thousand separator added | ||
expect(formatAmountDisplay('0.001200'), equals('0.0012')); | ||
}); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
\u001b
is a Esc character, i don't understand its benefit to the regex.