Page 1 of 1

Decimal points to whole numbers in Eos

Posted: Sat May 01, 2021 2:40 pm
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!

Re: Decimal points to whole numbers in Eos

Posted: Sat May 01, 2021 3:06 pm
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

Re: Decimal points to whole numbers in Eos

Posted: Sat May 01, 2021 4:32 pm
by intermolecularpyro
This works perfectly, thank you!