Skip to content

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
wants to merge 3 commits into
base: development
Choose a base branch
from

Conversation

zaelgohary
Copy link
Contributor

@zaelgohary zaelgohary commented Jun 4, 2025

Changes

  • Create formatAmountDisplay and use it in all amounts
  • Fix trailling zeros in amounts, Add thousand seperator
  • Use approximation symbol

Related Issues

Tested Scenarios

Included in transaction_helpers_test

@zaelgohary zaelgohary changed the title Fix small amount in Orders Format amount in Orders Jun 4, 2025
// User-friendly formatting based on amount size
if (doubleAmount >= 1000) {
// Large amounts: 2 decimal places max with thousand separators (e.g., 1,234.57)
formatted = decimalAmount.toStringAsFixed(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have the number as a Decimal or double. But you convert it to a string, then parse it again just to format it.
Use a NumberFormat directly on the already-parsed number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edited.

@zaelgohary zaelgohary requested a review from AlaaElattar June 23, 2025 05:35
formatted = formatted.replaceAll(RegExp(r'\.$'), '');
// Remove trailing zeros after decimal point only (if any), but keep approximation symbol if present
if (formatted.contains('.')) {
formatted = formatted.replaceFirst(RegExp(r'(\.\d*?[1-9])0+\u001b'), r'$1\u001b');
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants