• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML How to multiply with comma values?

Traversal

Member
Hi, I need your help again, to get things started :)

In my little test Project I wanted to multiply some values for Money.
I got the numbers 1598 and 13.76 which I stored in strings.
Now I did try to mulitply like this:

res = real(string1) * real(string2); // maybe using 'real' here is the Problem?

It works, but I can not get a float. I still receive a full integer and not a comma separated value.
Receiving: 21988 but should have gotten 21988,48
 
The code you posted is not the problem., I tested this and it worked:
Code:
string1 = "1598";
string2 = "13.76";
res = real(string1) * real(string2);
draw_text(100, 100, string(res));
Did you maybe write this?:
draw_text(100, 100, string_format(res,0,0));
 

Traversal

Member
The code you posted is not the problem., I tested this and it worked:
Code:
string1 = "1598";
string2 = "13.76";
res = real(string1) * real(string2);
draw_text(100, 100, string(res));
Did you maybe write this?:
draw_text(100, 100, string_format(res,0,0));

I am using it like this:

i_wertbtc = real(curbtc) * real(mybtc); //curbtc = 4512.15 mybtc=2
draw_text(10,140,string(i_wertbtc)); //Output = 9024.00 ; should be 9240,30!
 
H

Homunculus

Guest
Make sure curbtc is really "4512.15" and not "4512,15" . By using the first, I get the correct result, with the latter I only get the integer part.
 
I am using it like this:

i_wertbtc = real(curbtc) * real(mybtc); //curbtc = 4512.15 mybtc=2
draw_text(10,140,string(i_wertbtc)); //Output = 9024.00 ; should be 9240,30!
I tested this in GMS 2 and GM:S 1.4::
Code:
curbtc = "4512,15"; mybtc="2";
i_wertbtc = real(curbtc) * real(mybtc);
show_debug_message(string(i_wertbtc));

curbtc = "4512.15"; mybtc="2";
i_wertbtc = real(curbtc) * real(mybtc);
show_debug_message(string(i_wertbtc));
Note the only difference is a decimal point and a decimal comma.

And the output was the same in both GM versions:
9024
9024.30

So I guess @Catan might have had the answer for you.
 
Top