# 2.39999999999 instead of 2.4 / Zed's Tycoon Kit cant handle decimals

Im using Zed’s Tycoon Kit with a script that adds rebirths. Every rebirth adds .2 to a multiplier. The number never goes past the tenth decimal. So it will always be 1.2 or 1.6, never 1.22 or 1.66. But, when I collected \$2 dollars with a x1.2 multiplier, it would give 2.39999999999 instead of 2.4, making the Tycoon Kit’s script think the number is in the billions.

I was wondering if there is any easy fix to this, or if I have to edit the shortening script, how I can do that.

Shortener:

``````function module:ConvertShort(Filter_Num)
local x = tostring(Filter_Num)
if #x>=10 then
local important = (#x-9)
return x:sub(0,(important)).."."..(x:sub(#x-7,(#x-7))).."B+"
elseif #x>= 7 then
local important = (#x-6)
return x:sub(0,(important)).."."..(x:sub(#x-5,(#x-5))).."M+"
elseif #x>=4 then
return x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
else
return Filter_Num
end
end

return module
``````

Video:
robloxapp-20220620-2054544.wmv (4.9 MB)

Thanks for any help in advance.

IEEE 754 binary64 has a precision of 53 binary digits.
When it is tostring’d it converts the binary to the closest shortest decimal.

Since 1.2 and 1.6 cannot be exactly represented in the IEEE 754 binary64 format, it’ll represent the approximated version of these decimal expansions.

If you’re not going below one fractional places then you could create a rational data type with the denominator of 10 and the numerator as an integer using Luau VM number as it can represent integers from 0 to 253.

…or you could use `%.1f` specifier in `string.format` if you don’t want to implement a custom rational data type as that rounds the decimal expansion to one fractional places.

4 Likes

Try using math.floor(), or math.round() to remove the decimal.

``````local x = math.round(2.8) --> 3
local y = math.round(2.39999999999999) --> 2
local z = math.round(1000.23394839484) --> 1000``````
2 Likes

So I added the math.round to this part of another script, which actually calculates how much money to give you, and now instead of 2.4 getting added, it adds 4.

Am I doing something wrong here?

``````--If player has premium, add an additional .1 to the multiplier
-----------------------------
Stats.Value += math.round(Money.Value * (((PlrMulti/ 5)+ .1)+ 1))
-----------------------------
--But, if they dont, leave it to the base multipliers
else
-----------------------------
Stats.Value += math.round(Money.Value * ((PlrMulti/ 5)+ 1))
-----------------------------
``````

I wrote this for someone else but noticed this post. You can use something like `string.format("%2.f", number)` to use only up to 2 decimal places. However, numbers like `5` will become `5.00` that way, and, I know a lot of people don’t like that.

I posted this GitHub gist with the function I wrote which (attempts) to convert a number to a string up to a certain number of decimal places, and uses `math.round` to turn the numbers into integers.

It is not well made so, if it sounds fun, I encourage you to try and break it apart and understand it, and maybe improve upon it yourself, but, otherwise even though it is not great it does reproduce the behaviour you want for negative and positive numbers.

Here’s a version that does use string operations (e.g. string.sub):

And then here’s a previous version that doesn’t use string operations:

1 Like

you can also use this round function which will just round to the nearest decimal that you ask for.

``````-- Round 'x' to the nearest 'mult'

local function Round(x: number, mult: number): number
return math.round(x / mult) * mult
end
``````
1 Like

This does not work when `mult` is anything except `1`. This is because you round the number which causes lua to turn the number into an integer (it can store it as a `float` or an `int` and can change between them). But by dividing you’d be turning it back into a float, and the reason all the extra garbage gets added on the end is because floats can’t actually store every number (so what you are seeing is actually just the closest number that a float can store)

Additionally you’re actually doing this backwards, you wanted this but this still has the same issues:

``````math.round(x * mult) / mult
``````

I’d also like to note that my original gist did it without any string operations (that was one of the goals) but you can also really just use `string.sub` which is wayyy less convoluted.

Edit: Posted my implementation of that above

1 Like

Roblox is bad at maths acc every language is you would need to round it to a decimal place using topics here but i forgor which topic so search it. pls

The problem with this is that the tycoon kit will still think that 5.00 is 3 long when its actually 1 long, if you know what I mean. It will still mess up the shortener. I Can’t script so I dont know how to fix it at that level

This is what my GitHub gist is meant to solve, it cuts off the extra 0s from the number.