• 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!

Legacy GM (SOLVED) Transform a string into money

D

Daniel Polo

Guest
I need help manipulating strings.

ex:

global.money = 10000

draw_text(x,y,global.money)

The result is obviously: 10000

What i need is: 10.000

I took a look on the docs but i did not found anything related to this, and i'm pretty sure that has to be some easy way to do this.

And of course, sorry for my bad english.
 

YoSniper

Member
Script: convert_money_to_string(money)
Code:
var money_str, dummy_value, part, part_str;
money_str = "";
dummy_value = argument0;
while dummy_value >= 1000 {
    part = dummy_value mod 1000;
    part_str = "";
    if part < 100 {
        part_str += "0";
    }
    if part < 10 {
        part_str += "0";
    }
    part_str += string(part);
    money_str = "," + part_str + money_str;
    dummy_value = floor(dummy_value / 1000);
}
money_str = string(dummy_value) + money_str;

return money_str;
In case it's not obvious, I'm dividing the number into 3-digit sections. When needed, I'm filling in placeholder zeroes. Then, I separate each 3-digit section with commas (because I'm American, we use commas.)
You can just as easily replace the commas with dots.

Hope this helps!
 
D

Daniel Polo

Guest
This is exact what i needed. Thank you!

(Y)

Tag Brasil: Game Maker Studio transformar string em formato monetário, transformar string em formato de moeda.
 
Top