playMaker

Author Topic: Int's Float's and rounding  (Read 2625 times)

Sjones

  • Full Member
  • ***
  • Posts: 203
Int's Float's and rounding
« on: February 20, 2013, 08:55:02 AM »
This is something I have been battling for a while now, to use ints or floats

integers are better for performance reasons but floats will have to be used here and there for calculations etc.

tried doing some research to find out more about what the performance cost is and got no where, most people suggesting nowadays performance is else where. (opinions welcome on that)

so I have been leaning more towards using floats for the most part throughout the game, the issue I am now having is the float to string, the formatting options is great but it rounds to the last digit to the nearest of the proceeding digit.

I am wanting to output what is effectively currency in whole numbers to the player, as such I want it to always round down. (or I could get angry players saying they have enough, when actually its just rounded and they dont)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Int's Float's and rounding
« Reply #1 on: February 20, 2013, 09:48:02 AM »
I don't know how to control the rounding, but why wouldn't you do your calcs with floats and convert the final amount to an int that the player sees?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Int's Float's and rounding
« Reply #2 on: February 21, 2013, 01:29:49 AM »
extra processing, it was what I originally did set up, float to int - int to string - set text property

however with the float to string, you cut out a process, and say if you have 10 bits of text you want to update regularly thats an extra 10 processes you can skip (in my case per second)

if it is impossible to always round down then this will have to be used, but optimization is something I always strive for especially as the project is intended for mobile platforms.