How do I change this number (142.899) to a normal number that has no dot?
Thank you for your support!
I really appreciate it.
How do I change this number (142.899) to a normal number that has no dot?
Thank you for your support!
I really appreciate it.
Depends on if you mean you want the first value of the number before the decimal point or if you want the whole value just without the point. One way you could do it is by spiting the string with the thing it splits with being the decimal point and then getting the string you want either before or after the point.
Another method could be using :gsub
on a string with the first param being the dot and the second being an empty space to replace all dots with an empty string meaning you would just have the number rather then the number with the dot in.
All things you can do with the string can be found here: string | Documentation - Roblox Creator Hub
If you want to change it with a number (which is not in a string format) you can view all the stuff here: Numbers | Documentation - Roblox Creator Hub
Ok, I will double-check the script but I am not a scripter other Developer helped me.
Thankyou for your help.
To get ‘142.899’ as ‘142’:
local n = 142.899;
local Integer, _ = math.modf(n);
n = Integer;
print(n); -- output: '142'
To get ‘142.899’ as ‘142899’:
local n = 142.899;
local _, Decimal = math.modf(n);
n *= string.len(tostring(Decimal)); -- this may not work as excepted as of floating point rounding errors. I recommend not just straight up copying this code, and rather, finding a better workaround to this error.
print(n); -- output: '142899'
This is the script what I used
What do I change from here?
local save_digits = 6
local module = {}
function module.packNumber(number)
return number ~= 0 and math.floor(math.log(number) / math.log(1.0000001)) or 0
–local unpacked = string.format(“%.f”,number)
----unpacked creates floating error
–local length = string.len(unpacked)
–local index = string.len(string.sub(unpacked,save_digits+1,length))
–local value = string.sub(unpacked,1,save_digits)
–return tonumber(index…value)
end
function module.unpackNumber(number)
return number ~= 0 and (1.0000001^number) or 0
–local length = string.len(number)
–if length > save_digits then
– local index = string.sub(number,1,length-save_digits)
– local number = string.sub(number,length-save_digits+1,length)
– return number * 10 ^ index
–else
– return number
–end
end
return module
if you want to round it to the nearest integer, you can just do this in a local script:
local a = 256.55 -- your value
local rounded_a = math.floor(a + 0.5)
print(rounded_a) -- Output: 257
This is the script I used
What do i change from here?
local save_digits = 6
local module = {}
function module.packNumber(number)
return number ~= 0 and math.floor(math.log(number) / math.log(1.0000001)) or 0
–local unpacked = string.format(“%.f”,number)
----unpacked creates floating error
–local length = string.len(unpacked)
–local index = string.len(string.sub(unpacked,save_digits+1,length))
–local value = string.sub(unpacked,1,save_digits)
–return tonumber(index…value)
end
function module.unpackNumber(number)
return number ~= 0 and (1.0000001^number) or 0
–local length = string.len(number)
–if length > save_digits then
– local index = string.sub(number,1,length-save_digits)
– local number = string.sub(number,length-save_digits+1,length)
– return number * 10 ^ index
–else
– return number
–end
end
return module
From what I understand you’re trying to remove the decimal numbers. A simple solution would be using math.floor to remove the decimals.
TextLabel.Text = math.floor(Your number)
This script would round the number to the nearest integer.
Here is a clearer example:
local Number = 25.2332323
print(math.floor(Number)) -- 25
There’s math.round() which is easier.