• Godot Help
  • How to move decimal point left in floating point number?

Hey, trying to move my floats decimal point left, but unfortunately i only seem to be able to find code so far to move it right. I'm trying to avoid math to do this, but maybe it's no different, but if so I wanted to try and check to see if that will be the case that multiplying such simple numbers will not result in small inaccuracies over time. I only need this decimal place move when displaying this float as a string, cause to be honest the number is an integer to avoid inaccuracies as I found simple adding and subtracting with a float after 9 - 13 times started to cause extra work, so I'd rather work with something I do the same accurate math every time and have to do a little extra work every time to display how I'd like it to

Thanks!

  • Well you can just multiply or divide by 10. That moves the decimal place, however with floating point numbers it won't be exact to every place.

    If you just need it for display purposes, you can cast it to a string, then find the . with the string search functions and just swap the substring of that character and the one to the left.

    You can see the String functions available here: https://docs.godotengine.org/en/stable/classes/class_string.html

Well you can just multiply or divide by 10. That moves the decimal place, however with floating point numbers it won't be exact to every place.

If you just need it for display purposes, you can cast it to a string, then find the . with the string search functions and just swap the substring of that character and the one to the left.

You can see the String functions available here: https://docs.godotengine.org/en/stable/classes/class_string.html

    cybereality Geez I didn't really think about manipulating the string once I failed with using the string manipulation for adding decimal point to the end. Thank you!