Skip to main content
More specific title. Collapsed unnecessary two-item bulleted list. Formatting for code entities. Simplified grammar.
Source Link
Anko
  • 13.4k
  • 10
  • 55
  • 82

Float or int What data-type should I use for in-game currency?

In a simple business simulation game (built in Java + Slick2D), which is more suitable to store theshould a player's current amount of money: be stored as a floatfloat or an intint, or something else? Some information:

  • Most of the transactions will use cents ($0.50, $1.20 and so on)
  • There will be interest rate calculations at some point. Simple ones though.

In my use-case, most transactions will use cents ($0.50, $1.20, etc.), and simple interest rate calculations will be involved.

I've seen people saying you should never use floatfloat for currency, as well as people saying you should never use intint for currency. I feel like I should use intint and round any necessary percentage calculations. What's the best solution in this caseWhat should I use?

Float or int for currency?

In a simple business simulation game (built in Java + Slick2D), which is more suitable to store the player's current amount of money: a float or an int? Some information:

  • Most of the transactions will use cents ($0.50, $1.20 and so on)
  • There will be interest rate calculations at some point. Simple ones though.

I've seen people saying you should never use float for currency as well as people saying you should never use int for currency. I feel like I should use int and round any necessary percentage calculations. What's the best solution in this case?

What data-type should I use for in-game currency?

In a simple business simulation game (built in Java + Slick2D), should a player's current amount of money be stored as a float or an int, or something else?

In my use-case, most transactions will use cents ($0.50, $1.20, etc.), and simple interest rate calculations will be involved.

I've seen people saying you should never use float for currency, as well as people saying you should never use int for currency. I feel like I should use int and round any necessary percentage calculations. What should I use?

edited tags
Link
sam hocevar
  • 23.9k
  • 2
  • 64
  • 95
Tweeted twitter.com/#!/StackGameDev/status/282153978777706496
Source Link
Lucas Tulio
  • 1.3k
  • 1
  • 11
  • 17

Float or int for currency?

In a simple business simulation game (built in Java + Slick2D), which is more suitable to store the player's current amount of money: a float or an int? Some information:

  • Most of the transactions will use cents ($0.50, $1.20 and so on)
  • There will be interest rate calculations at some point. Simple ones though.

I've seen people saying you should never use float for currency as well as people saying you should never use int for currency. I feel like I should use int and round any necessary percentage calculations. What's the best solution in this case?