- Thread starter marasovec
- Start date

Use string_format() to restrict the number of decimal places.

Except that you do expect perfection when adding 0.5 to 0, as both are exactly representable as floating point numbers and their sum is exactly 0.5.I will NOT expect perfection under the decimal point when dealing with floating-point arithmetic.

Use string_format() to restrict the number of decimal places.

This is NOT an issue with floating point arithmetic.

Actually, you've got it the other way around in your title.Is there a way to fix this?Code:`draw_text(x, y, string(0.5)); // 0.5 var num = 0; num += 0.5; draw_text(x, y, string(num)); // 0.50`

As the documentation states (https://docs.yoyogames.com/source/dadiospice/002_reference/strings/string.html):

It is expected to see 0.50 in both cases.If the real number is an integer, it will be saved with no decimal places, otherwise, it will be saved with two decimal places.

I currently can't test this myself, but if you're right, it is the result of GameMaker trying to optimize your program by calculating the result of string in a preprocessing step, before running the program, and making a mistake in this calculation.

If you know beforehand the exact amount of digits you want, then that's indeed the perfect solution.It works nicely. Thanks!

I've tested it. (GMS 1.4.9999)It is expected to see 0.50 in both cases.

I currently can't test this myself, but if you're right, it is the result of GameMaker trying to optimize your program by calculating the result of string in a preprocessing step, before running the program, and making a mistake in this calculation.

Also sometimes it shows "-0.0" which is quite interesting