Split String.num()
into two functions: num_float
and num_simple
#11277
Labels
Milestone
String.num()
into two functions: num_float
and num_simple
#11277
Describe the project you are working on
This applies to all Godot Engine projects.
Describe the problem or limitation you are having in your project
As of #7894 and godotengine/godot#47502, the number-to-string functions in Godot look like this:
num
float
.0
), always float literal.num_scienfitic
float
num_int64
int
num_uint64
int
str
Variant
All of the
num
* functions are in String, butstr
is a global function.There are 2 problems here:
.0
..0
would be added for whole numbers.Describe the feature / enhancement and how it helps to overcome the problem or limitation
My proposal is to split
num
into two functions so that it looks like this:num
float
num_float
(or maybenum_simple
for 4.3 compat?)num_float
float
.0
), always float literal.num_simple
float
num_scienfitic
float
num_int64
int
num_uint64
int
str
Variant
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The proposal would work like this, all three should happen in the same PR:
num
tonum_float
.num_simple
function that works likenum
did in Godot 4.3.num
tonum_float
to keep existing code running.Or, alternatively:
num
tonum_float
.num_simple
function that works likenum
did in Godot 4.3.num
tonum_simple
to keep existing code working like it did in Godot 4.3 and earlier.If this enhancement will not be used often, can it be worked around with a few lines of script?
Yes, trivially, but confusingly, and inefficiently:
String.num(my_float).trim_suffix(".0")
Is there a reason why this should be core and not an add-on in the asset library?
Converting numbers to strings is core.
The text was updated successfully, but these errors were encountered: