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 a String method to format numbers with a delimiter separator and custom decimal separator #9289

Open
Calinou opened this issue Mar 12, 2024 · 2 comments · May be fixed by godotengine/godot#89424

Comments

@Calinou
Copy link
Member

Calinou commented Mar 12, 2024

Describe the project you are working on

The Godot editor 🙂

Describe the problem or limitation you are having in your project

Large numbers are currently displayed as-is in the editor, without any separators for thousands. Additionally, projects regularly need to display large numbers for debugging purposes, and readability is important in this scenario.

This is also a common use case for management or idle games which often display large numbers.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

By adding a String.number_format() method (and having TextServer use it internally when relevant), we can improve the display of large numbers in the editor:

Screenshot_20240311_224042 Screenshot_20240311_235852 Screenshot_20240311_235917

TextServer takes the current language into account and aims to use the correct separator for the language. Here's an example with French:

Screenshot_20240312_000354

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

  • String.format_number() can be used directly when you want to specify your own separator characters, a custom separator interval or don't need internationalization. Custom separator intervals can be useful for hexadecimal numbers (e.g. 0x00060d07 can become 0x0006 0d07).
  • TextServer.format_number() uses String.format_number() with an automatically detected delimiter separator and decimal separator according to the current language (or the specified language parameter).

If this enhancement will not be used often, can it be worked around with a few lines of script?

This can be worked around with a script, but not for the editor's own display of large numbers.

Is there a reason why this should be core and not an add-on in the asset library?

This is about improving editor usability as well as quality of life when debugging a project.

@charliewhitfield
Copy link

charliewhitfield commented Jun 7, 2024

Two questions about this proposal:

  1. Does this affect the Output window (i.e., output from print statements)? [Edit: sorry, I think I see this in the first image.]
  2. Would I be able to supply my own format_number() function in an editor plugin?

I'm asking because I also have the "small number problem", where the editor prints "0" when the number is neither 0.0 nor approximately 0.0 by is_zero_approx() test. This happens quite frequently in my solar system simulation.

@Calinou
Copy link
Member Author

Calinou commented Jun 8, 2024

  1. Does this affect the Output window (i.e., output from print statements)? [Edit: sorry, I think I see this in the first image.]

It wouldn't, but you could use the number formatting method manually within a print() if you wish. The first image is the 3D editor viewport's View Information panel, not the Output bottom panel.

  1. Would I be able to supply my own format_number() function in an editor plugin?

You could choose to use a custom separator for thousands and decimals, as well as choosing the "length" of thousands so to speak. The PR's String.format_number() method provides all three options as optional parameters.

I'm asking because I also have the "small number problem", where the editor prints "0" when the number is neither 0.0 nor approximately 0.0 by is_zero_approx() test. This happens quite frequently in my solar system simulation.

This is a different issue: godotengine/godot#78204

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

Successfully merging a pull request may close this issue.

2 participants