Code: draw_text(x, y, string(0.5)); // 0.5 var num = 0; num += 0.5; draw_text(x, y, string(num)); // 0.50 Is there a way to fix this?
Repeat after me: 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.
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. This is NOT an issue with floating point arithmetic. Actually, you've got it the other way around in your title. 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. 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.