# Legacy GM[SOLVED] draw_string draws "0.50" instead of "0.5"

#### marasovec

##### Member
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?

#### FrostyCat

##### Member
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.

#### marasovec

##### Member
It works nicely. Thanks!

#### jo-thijs

##### Member
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.

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?
Actually, you've got it the other way around in your title.
If the real number is an integer, it will be saved with no decimal places, otherwise, it will be saved with two decimal places.
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.

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

#### marasovec

##### Member
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.
I've tested it. (GMS 1.4.9999)
Also sometimes it shows "-0.0" which is quite interesting 