Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Money changing

Hey everyone,

I got a small question within the scripting or database changing..
When in shops or in the menu, you see your money as whole numbers. My question is, is it possible with a script or anything to work with comma's, so you can define cents etc.

So I mean, if something costs 1,75 I can just define it like that instead of 175

It would be cool, because I can use real prices, because I'm working on a game which should represent a town for a school project.

Thanks in advice..
 

poccil

Sponsor

Usually that can be achieved using the sprintf function.  Here's an example:

Code:
  string = sprintf("%.2f",number)

That code above prints the number, but with a period as a decimal point.  If, however, you insist on
using a comma as a decimal point, then it can be converted further:

Code:
  string = sprintf("%.2f",number)
  string.gsub!(/\./,",")

I hope this helps.
 
Anyplace where 'gold' is displayed...  (search for 'price' or 'gold')

Window_Gold, Window_ShopBuy, Window_ShopNumber (I think that's all...)

Code:
#    self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
    gold = sprintf("%.2f",$game_party.gold)
    self.contents.draw_text(4, 0, 120-cx-2, 32, gold, 2)

Be Well
 
I used your example in the window_gold and tested it.

During the testing, I found some money with the comma, but it just pasts .00 behind it.
I had 1000 for example, but it showed 1000.00. But I would like it that the comma gets on the normal place, instead of pasting it at the end.

Like if I add 1000 gold to the party, it should say 10.00 instead of 1000.00, or atleast if it's possible to change the last numbers.

Thanks in advice, and sorry for the multi-asking. But it's hard to explain.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top