0 votes

Sometimes when I use round(), I get -0 because of division by negative integer. Does anyone know any quick and simple ways to get just 0 when doing this in general?

in Engine by (56 points)

Can you give us an code example?

That smells like a bug. -0 is a surreal number that has not to exist.

One possible option is to use int(round(x)) instead of round(x).

For example, print(int(round(1.0/(-3)))) displays 0, whereas print(round(1.0/(-3))) displays -0.

1 Answer

+1 vote

You can use abs()

by (141 points)

As in abs(-0) == 0 is always true

This answer produces the most readable code.

What if I am working with a Vector2()?

If one of the values--either x or y--is -0, what are any quick/ simple ways to covert a vector for example?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.