Skip to content
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

🚀 Add number format expression #4663

Closed

Conversation

AyhamAl-Ali
Copy link
Member

@AyhamAl-Ali AyhamAl-Ali commented Mar 15, 2022

Description

Add a new function to format numbers like 123,456,789


Target Minecraft Versions: Any
Requirements: None
Related Issues: None

@AyhamAl-Ali AyhamAl-Ali added the feature Pull request adding a new feature. label Mar 15, 2022
@AyhamAl-Ali AyhamAl-Ali marked this pull request as ready for review March 15, 2022 22:15
@AyhamAl-Ali AyhamAl-Ali marked this pull request as draft June 24, 2022 08:51
@AyhamAl-Ali AyhamAl-Ali marked this pull request as ready for review April 21, 2023 23:13
@AyhamAl-Ali AyhamAl-Ali marked this pull request as draft April 30, 2023 16:09
@AyhamAl-Ali
Copy link
Member Author

AyhamAl-Ali commented Apr 30, 2023

Marking as Draft until I find a fix for the syntax conflict with ExprFormatDate (when using variables)

Copy link
Member

@Moderocky Moderocky left a comment

Choose a reason for hiding this comment

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

I am wondering whether this might actually be better as a built-in function (of the style formatNumber(number, pattern)), rather than as a syntax.
My concerns are threefold:

  1. This a %thing% ... %thing syntax pattern, which is painful to parse.
  2. The syntax feels a little clumsy, e.g. 10 formatted human-readable with "###" doesn't sound very English. This isn't your fault; I'm not sure if there is a nice way to phrase this.
  3. I'm worried people might confuse 'formatted as' with 'parsed as' and try to misuse this, especially since it's specific to numbers currently.

This is just a suggestion, if you feel syntax is better than a function then that is fine.

@AyhamAl-Ali
Copy link
Member Author

I am wondering whether this might actually be better as a built-in function (of the style formatNumber(number, pattern)), rather than as a syntax. My concerns are threefold:

1. This a `%thing% ... %thing` syntax pattern, which is painful to parse.

2. The syntax feels a little clumsy, e.g. `10 formatted human-readable with "###"` doesn't sound very English. This isn't your fault; I'm not sure if there is a nice way to phrase this.

3. I'm worried people might confuse 'formatted as' with 'parsed as' and try to misuse this, especially since it's specific to numbers currently.

This is just a suggestion, if you feel syntax is better than a function then that is fine.

This is a very good suggestion.. it will fix the major parsing issue of this syntax and formatted date syntax because they both are identical.

@Moderocky Moderocky force-pushed the master branch 2 times, most recently from bd134d0 to 3f08853 Compare September 16, 2023 16:59
@AyhamAl-Ali AyhamAl-Ali marked this pull request as ready for review April 5, 2024 23:01
@AyhamAl-Ali AyhamAl-Ali changed the base branch from master to dev/feature April 5, 2024 23:02
@AyhamAl-Ali AyhamAl-Ali requested a review from Pikachu920 April 6, 2024 01:41
Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

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

Nice work!

"command /formatnumber <number>:",
"\taliases: fn",
"\ttrigger:",
"\t\tsend \"Formatted: %formatNumber(arg-1)%\" to sender"
Copy link
Member

Choose a reason for hiding this comment

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

Some more examples of how to use DecimalFormat would be nice. The table on the javadocs is good, but pretty dense for new users.

@@ -0,0 +1,17 @@
test "formatted numbers function":
Copy link
Member

Choose a reason for hiding this comment

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

Make sure to test invalid numbers too! NaN, infinity, null values, etc.
Floating point would also be good to show.

Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

looks good apart from sovde's requested changes. feel free to re-request my review after those changes are made.

@Efnilite
Copy link
Member

Continued in #7166

@Efnilite Efnilite closed this Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Pull request adding a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants