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.

Getting rid of decimal points

I'm making a fishing system, and the "algorithm" I dun chose for the exp unfortunately leaves it with a decimal place at the end.

So, like... 127 / 225.77890632 exp

As this is shown visually, it's not exactly nice to look at.

From the help file, I found that .ceil would round it up, or .truncate would get rid of any places.

I've tried each seperate. I've even tried one after the other... Neither works.

Code:
  def levelup
    $game_variables[28] += 1
    $game_variables[44] *= 1.75
    $game_variables[44].ceil
    #$game_variables[44].truncate
    $game_variables[27] = 0
    @help.set_text('Your fishing rank is now ' + $game_variables[28].to_s + '!')
  end

Any ideas?

Edit: Notes:

[27] = fishing exp
[28] = fishing level (rank)
[44] = exp for next level
 

Zeriab

Sponsor

$game_variables[44] = $game_variables[44].ceil
$game_variables[44] = $game_variables[44].truncate
$game_variables[44] = $game_variables[44].to_i

pick whatever you like ^^
 

Zeriab

Sponsor

It's because the .ceil method is not destructive. (Same with the others)

You can also do this if you want
$game_variables[44] = ($game_variables[44]*1.75).to_i
after all $game_variables[44] *= 1.75 is the same as $game_variables[44] = $game_variables[44] *1.75

*hugs*
- Zeriab
 

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