Decimal points to whole numbers in Eos

All about the past, current and future webteases and the art of webteasing in general.
---
Post Reply
intermolecularpyro
Explorer
Explorer
Posts: 51
Joined: Wed Jan 15, 2020 8:19 am

Decimal points to whole numbers in Eos

Post by intermolecularpyro »

Hi everyone!

In the tease I'm making at the moment I have a user defined point value being multiplied by a random factor of 0.1, 0.2, 0.3 etc. up to 1.9.

It works totally fine for multiples of 10, but otherwise it can result in non-whole numbers, especially when done more than once as is the intention (after a few tries it can result in over 10 decimal places).

Is there a way to round up (or down) this value to the nearest whole number?
If that's not possible, can I make a user input accept only multiples of 10?

Hope you guys can help!
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: Decimal points to whole numbers in Eos

Post by fapnip »

Code: Select all

Math.floor(1.99) // will return 1
Math.ceil(1.2) // will return 2
Math.round(1.2) // will return 1
Math.round(1.99) // will return 2
See:
https://www.educative.io/edpresso/mathc ... javascript
intermolecularpyro
Explorer
Explorer
Posts: 51
Joined: Wed Jan 15, 2020 8:19 am

Re: Decimal points to whole numbers in Eos

Post by intermolecularpyro »

This works perfectly, thank you!
Post Reply