Why the rotation_degrees in the UI of godot does not match with the real value

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SebaBear

Hello ! When I was trying to program an interactive button today I discovered something very strange . I set the rotation_degree of a node in the UI to 90 and tried to print it’s value using a scrip so … print(rotation_degrees) … but (dramatic music) instead of 90 it got 90.000206 . I repeated the experiment with other nodes and the same thing happened. Is there any explanation ?

:bust_in_silhouette: Reply From: Zylann

Looks like a float precision error. This is quite common to see, especially when knowing that the real value is actually stored in radians, so it has to be converted to degrees when using rotation_degrees, and a bit of precision goes off as it does that.

If you rely on perfect equality of a float property, you should do so with an error margin, or using > or <, as it’s very likely it won’t be exactly equal in some cases.

Thanks bud ! I converted the value to an int for precision since I didn’t care about the fractional part.

SebaBear | 2020-05-15 14:38