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?
#Too many decimals
44 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
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
I also want to be able to get decimal numbers
So, depending on the digits variable, it should be rounded on that specific decimal
Math.round(Utils.random.nextDouble(0, 2), 2)
I think this generates 0 -> 1.99
Sorry for beiong so anoying, but I want to first multiplie the number with the other stuff and then floor it...
when u want to floor it, why u just don't use Math.floor? 
and what stops you?
I dont quite 100% get what you want. You want to multiple with decimals but at the end not?
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
then just dont bother about having 1.000000001
I am doing this for the random generation of my gems, and I display the number in the item lore
Otherwise I get stuff like this
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
No, because some of the numbers are used in calculations that only allow full numbers
Text.translate is your friend
floor it where it needs
no, floor removes all decimals
(Math.round(x * 100) / 100).toFixed(2); is probably a way
he said his stuff don't allow decimals
at some point
some do, some don't as he said
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?
not a good way of designing
hold raw numbers in place
and for the user, format them
not format them in place
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
thats just how floating point numbers are calculated, javascript probably also follows IEEE standard
there are probably a lot better youtube videos explaining this than some discord thread can
Ok, thanks