#Too many decimals

44 messages · Page 1 of 1 (latest)

north prism
#

This is part of my code; js +((Math.random()*tier*selectedAttribute.multiplier).toFixed(selectedAttribute.digits))
Don't worry about all the variables, basicly I get a random number, multiplie it with some stuff, set it to either 0 or 2 digits using toFixed, and when I want to convert it back to a number, it gives me like 1.000000000001, which is so anoying. Any idea why this happens or how I can set stuff to a specific number of digits?

copper fernBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

light abyss
#

Utils.random.nextInt(0,3)

#

please test, don't remember if it is 0,3 to generate 0, 1, 2

#

yeah, uses 0,3 to generate 0, 1 and 2

north prism
#

I also want to be able to get decimal numbers

#

So, depending on the digits variable, it should be rounded on that specific decimal

light abyss
#

Math.round(Utils.random.nextDouble(0, 2), 2)

I think this generates 0 -> 1.99

north prism
#

Sorry for beiong so anoying, but I want to first multiplie the number with the other stuff and then floor it...

fallen minnow
#

when u want to floor it, why u just don't use Math.floor? hmmjj

north prism
#

Because I can't set the decimals for it

#

It only does full numbers

fallen minnow
#

I dont quite 100% get what you want. You want to multiple with decimals but at the end not?

north prism
#

I want to get a random number, multiplie it with some stuff and lastly set it to s specific amount of decimals

#

That amount of decimals is also stored in a variable

fallen minnow
#

then just dont bother about having 1.000000001

light abyss
#

why

#

are you displaying this number?

north prism
#

Otherwise I get stuff like this

light abyss
#

you are formating your number too soon don't you think?

#

just store your value as it is

#

and at display time, format as you need

north prism
#

No, because some of the numbers are used in calculations that only allow full numbers

light abyss
#

Text.translate is your friend

fallen minnow
#

no, floor removes all decimals

#

(Math.round(x * 100) / 100).toFixed(2); is probably a way

light abyss
#

he said his stuff don't allow decimals

#

at some point

#

some do, some don't as he said

north prism
#

I just liked the idea, to do everything when first making the number

#

Less stuff to do later

#

But, does anyone have an idea why this happens in the first place?

fallen minnow
#

not a good way of designing

#

hold raw numbers in place

#

and for the user, format them

#

not format them in place

north prism
#

Yeah, fine

#

I still want to know why converting a string number with 2 decimals into a normal number gives it like 10 decimals somethimes

fallen minnow
#

there are probably a lot better youtube videos explaining this than some discord thread can

north prism
#

Ok, thanks