#How do I properly round a float?
6 messages · Page 1 of 1 (latest)
You could check witch float_value == roundf(float_value). This will compare the value to itself but rounded. It'll return true if it is a whole number and false if it's not.
yes, but how does that solve my problem?
return ("%.3f" % number).strip_edges(true, true) + "e" + str(exponent)
I tried this but it only printed with the .000
%.3f will ensure that the 3 numbers after the comma are there.
How about replacing %.3f with %s if it is a whole number? That would give it to ya normally.
func clean_numstr(str: String) -> String:
var i = str.length() - 1
while i >= 0 and str[i] == "0":
i -= 1
if i >= 0 and str[i] == ".":
i -= 1
return str.substr(0, i + 1)
return clean_numstr("%.3f" % number) + "e" + str(exponent)
This worked for me