The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+6 votes

So I'm new and confused.

var gravitational_constant = 6.67e-11
var mass = 1.1e15
var test = 0.000000000667


and i get this


So from what I gather var is enough to assign a large number, but not using scientific notation? but print() accepts it?
Also how do I assign small float values not even the print function recognises that one?

in Engine by (18 points)

I have the same problem, I'm looking for change to scientific notation when the number is too long to display in a line.
u_u somebody can help?

SerK: That's an entirely different question. I suggest creating a new question for this, rather than commenting on an existing question.

You are right.

1 Answer

+2 votes

Happened upon your old question.

  1. Godot string formatting is really, really basic. You need to write (or copy) your own routines for adding commas, scientific notation and the like.

  2. The exact maximum for floating point numbers may or may not be platform specific: it is annoyingly hard to tell. The number is low enough that you will need to jump through hoops for the idle game genre (where 1.0e9999 is just another number). For today's MacOS, any floating point constants greater than 1e512 will give you an error
    built_in_strtod: Exponent too high
    <C++ Source> core/ustring.cpp:2076 @ built_in_strtod()

  3. You can use mine (public domain). Call it like this:
    print("This is scientific: %s %s" % [As.scientific(0.000123), As.scientific(1234.56, 4)])
    Put the file anywhere in your tree. I tend to put static utilities under ./util.

  4. Have a wonderful day.

Keep hacking! Keep notes. -- Charles

by (335 points)
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 Frequently asked questions and 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 [email protected] with your username.