If I have a number. Lets say it’s 2.32565343767, how can I round it to the nearest tenth? Like how can I turn the number into this: 2.3. I don’t want to round it to the nearest whole number (Because that’s not my goal here).

3 Likes

You can simply search for the first number behind the `.`

(in your example it’s 3) and do a simple algorithim that checks if the number behind that number (in your case it’s 2) is less than 5, or equal or higher than 5, if it’s less the number will stay the same, if it’s not you will add one to the first number (meaning 3).`

```
local number = 2.32565343767
local function round(num)
local str = tostring(num)
local first = tonumber(str[string.find(str, ".")+1])
[[UNFINISHED CODE]]
```

2 Likes

This is not efficient, especially when the solution is as simple as that

```
function round(n)
return math.floor(n * 10) / 10
end
```

6 Likes

I do realise that! I was going to add a lot to my post but his answer was already answered

1 Like