-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Always add decimal when converting float to string #47502
Conversation
Does this change apply automatically to floats within Vectors/Colors/Transforms/Matrices as well? |
Hmm, it doesn't. Changing it might be not as easy :I |
Ok, so I extended this to these types (in addition to floats): Vector2, Rect2, Vector3. |
Also need to solve this problem:
|
The precision problem doesn't look related. |
The problem is not with the precision of the numbers themselves, but that |
Ah, right. I don't know how to fix this tbh. I can't use Well maybe I could search for |
Ok changed it. Here's the FLOAT_STRING as it was originally:
The new one is slightly less efficient, but maybe it doesn't matter that much. |
We approved the change in a PR review meeting today, though we were concerned about the performance cost of the A better option might be to use |
Rebased and reworked. I removed the macro and just changed usages of
->
|
So I just noticed that changing |
modules/gdscript/tests/scripts/parser/features/nested_arithmetic.out
Outdated
Show resolved
Hide resolved
This seems to break the generated Mono glue:
CC @godotengine/mono |
@akien-mga It's likely because the bindings generator now generates code using literal The generator uses godot/modules/mono/editor/bindings_generator.cpp Lines 3188 to 3207 in 44516d1
godot/modules/mono/editor/bindings_generator.cpp Lines 3251 to 3287 in 44516d1
For example, we use it to generate |
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.
For the Mono bindings generator, we'll probably need to manually generate each piece of the constructor.
Tangentially related, the more time passes the more appropriate it looks to me to trim the trailing zero out of SpinBoxes. Whether that should be a setting or just done intrinsically is up to debate.
Could this be a placeholder modifier for format Strings? Is there also a programming language that faces a similar issue? If yes, what's their solution? It's looking like this PR is only objectively favoured when printing floats, but actually having that work would be vastly inconsistent with the |
Regardless, we should provide methods for each style of behavior. Users shouldn't need to write Would anyone like to propose APIs for these cases?
|
I think this change causes my project that runs fine in 4.3 to throw errors in 4.4 dev4. I have several data files generated by a separate C# app, where keys in a dictionary are ints that can be referenced by other data files. The trick is that C# exports JSON dictionaries with int keys as strings instead, and I have not found a way to disable/change that behavior, so when I go to do that lookup I end up with something like This isn't a difficult change for me to make, but it's a surprise than this applies to all numeric values loaded from JSON. |
You can't change this behavior, because the JSON format only supports strings as keys. Trying to use an int as a key would make it no longer a valid JSON file. I'm curious where you are getting |
var current_level: int = 12
print(current_level) would print 12 before this PR, but now prints 12.0 var current_level: int = 12
while current_level > target_level:
level_holder.get_node("Level" + String.num(current_level)).hide() the fix after this PR var current_level: int = 12
while current_level > target_level:
level_holder.get_node("Level" + String.num(current_level).replace(".0","").hide() Edit: This PR has broken all my serialization, its not just the above. All my integers which are converted to string suffixes to search files, don't work |
Thank you for the swift response - was already changing my conversions so I am glad you replied before I continued. |
I'm pretty sure this is the right thread--- With sign(), specifically, it used to return 1, 0, -1. And since 1 as an integer isn't the same thing as 1.0, anything that tries to, say, match a value with sign() will not work as intended. Also, a related weird thing that is definitely happening on Linux... If you have a variable like ..if you iterate over the values in the dictionary, it'll recognize the former as an int, and the latter as a float. But when you use |
Neither of the above seem to happen in v4.4.dev.custom_build [06bb994]: print(type_string(typeof(sign(2)))) # Prints int
print(type_string(typeof(sign(2.5)))) # Prints float
var dict: Dictionary[String, Variant] = { "thing_one" : 1, "thing_two" : 1.0, }
print(dict.values()[0]) # Prints 1 And they would not be caused by this PR, either way. |
Note that |
To be clear, the only thing changed by this PR is that floating-point numbers with a whole value (which is not the same thing as integers, So if you thought you were dealing with integers and this PR has changed those numbers to have a |
Hello, I needed a feature included only in 4.4 version. So I switched my project. But I'm currently having a problem with this pull feature now. All integer values are returning wrong in WebApi responses. For example; item_id stored as 1 is now 1.0. When I set this responses in a "json" object, all i see is values like 1.0, 2.0 etc. Now I have to convert whole project responses prior to that which is 19k lines of codes. Isn't there an option to change this in a projectwide? Edit: I suspected something during serialization; while getting HTTP responses; I am using "JSON.parse_string(body.get_string_from_utf8()" as suggested in official documents. If ".0" appears at the end of integer values just because we are using "get_string_from_utf8" function, this needs to be fixed. |
JSON doesn't have an integer type. Instead, it only has a |
Problem here is you can't deny lots of people using serialization and api results are always the same just because of a .0 extension to an integer value as i never saw before in any other languages. Now all data we have been using requires a deep refactoring. PR should have been confirmed after a little thinking about consequences. |
JSON is a standard. It does not have "integers". You seem to have been misusing the standard. This PR's main goal was to make floats vs integers explicit and it surfaced that a lot of folks have been using one when they meant the other. |
Oh sir, please read what i am telling up there and try to understand my point. JSON has integers or not, that's no matter. One way or another serialization is part of lots of projects. IF a PR effecting a common usage, you have to "think" about the consequences before applying it. This PR is affecting usage of serialization clearly because it seems like anything inside the "get_string_from_utf8" forced out to print ".0". In a very basic response of mine; sql stores the value as 1, WebAPI stores the value as 1. But Godot converts it to 1.0 during serialization. Just why? What would happen if you apply this PR to a language like Javascript. Can you imagine the chaos? Well I took a look at whole issues and repository logs here and I don't understand why Godot developers became so arrogant. Everyone has a meaningless fanaticism over things. Anyway I'm simply saying again; this PR made a method meaningless that has been used frequently. |
As said above, the JSON specification does not distinguish between @tool
extends EditorScript
func test(value):
var decoded = JSON.parse_string(JSON.stringify(value))
prints(value, type_string(typeof(value)),
"->", decoded, type_string(typeof(decoded)))
func _run():
test(1)
test(1.0) 4.3:
master:
Although I'm sorry to hear that this seems to have been a significant nuisance for you. However, you probably already had hidden bugs due to Godot's non-obvious behavior. It's possible that the bugs didn't show up because of implicit type conversions, but it's too risky and fragile to rely on that. This change just exposed the real problem, the mismatch between your expectations and how it actually works. Regarding conversions between native and JSON types, we recently added a new API that is intended to be as preserving and unambiguous a conversion as possible. Unfortunately the current implementation has several flaws, so I've opened PR #99765 to fix them. |
Thank you for your reply sir. Honestly I had upgraded from 4.2 to 4.4. I literally had no idea, 4.3 also had this conversion. Thanks for the #99765 |
…-the-trailing-zero Update documentation's "Prints" comments after #47502
So that
prints
Makes working with numbers less confusing. I remember someone mentioned it around godotengine/godot-proposals#1866
Closes godotengine/godot-proposals#7894