[SOLVED] Numbers won't round for simulation game (like 1000.000000000001)


Whenever I press any of the game’s “Upgrades” (“Comfort” button and others grouped alongside it) it should add only whole numbers to each song’s PayOut number that dictates how much you get for listening.

I’m having a lot of trouble getting the number displayed with each song to remain a whole number. I’ve added whole bunches of zeroes to the numbers to attempt to round them more effectively, and also added a few “precision: 1” functions too.

The logic to operate these buttons and the text displayed are globals.js, clairText.js, raindropText.js, mapleText.js, gymText.js, and mountainText.js.

I really truly can’t figure out how to make the number display as a whole number every time. If you click each of the upgrades up to Level 4, you’ll see how some buttons create bonuses like +99.999999999999991 instead of +100 and so forth.

Use Math.round with the number : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round


this.element.text = Math.round(songPayout);

Worked perfectly!

For anyone who needs similar help in the future, since I was displaying the number using concatenation, I had to format it as…


Thank you so much!

1 Like