I am currently doing a rebirth system. However I encountered a problem, the value becomes weird and makes results like: 1.6777777777997949 or 1,7878958759
I tried to google to see if I couldn’t find a solution, but it only gave me solutions that didn’t seem to work.
I wish someone could tell me how to fix this, thank you very much!
local value = 1.6777777777997949
print(math.ceil(value)) --prints rounded up
print(math.floor(value)) --prints without a point
print(string.format(“%.3f”, value)) --prints with 3 digits after the point
uh can u show the script of the value changing also as 2122jay said, do math.floor(value) if u dont want point
The script is really simple, it is:
Rebirths = 1
while (true) do
wait(1)
Rebirths += 0.1
print(Rebirths)
end
But I want the value to be passed this way: 1.7 and not this way: 1.76579853953432131 and 2
string.format("%.1f", 1.76579853953432131)
Not the best with patterns, but if you don’t want the decimal points to get rounded for some reason then you can do something like this:
string.format("%.1f", math.floor(1.76579853953432131 * 10) / 10)
I had the same problem in my project too. You just need to use int values, because some non-int values with number after decimal point may broke and count some ± extra values. So, to avoid it: store numbers in integers, and divide them when it’s needed to show to user. Basically you just need to multiply your variable on amount, that you dont wanna lose, like, If I had a number 0.01, Ill store it like 100, and then divide it, when needed.
For example:
local a = 1 --For example, its 1 gramm
myWeightText.Text = tostring(a / 1000) --that will change the text of UI element to actual Kilogramms view, so I will get something like: 0.001