Ex_Bla
(GroupHolder)
August 28, 2021, 4:14pm
#1
Hey! I have a placement system and I need a way to round a number to the nearest 0.5, yes I’ve already searched this topic and found a few posts that really didn’t help at all. So here’s an example of what I’m trying to accomplish, so here’s a few examples

etc, I haven’t been able to find a way to do this though. Any ideas?

iBuzzes
(Ryan)
August 28, 2021, 4:17pm
#2
You can use math.round

```
local number = 1.0
print(math.round(number)) --> 1
```

MrMoled
(Theo)
August 28, 2021, 4:17pm
#3
use this:

```
function SnapPosition(original, size)
local snapped = Vector3.new()
snapped = Vector3.new(
math.floor(original.X / size + 0.5) * size,
math.floor(original.Y / size + 0.5) * size,
math.floor(original.Z / size + 0.5) * size
)
return snapped
end
```

original : vector3
size : float (decimals or ints)

1 Like

Ex_Bla
(GroupHolder)
August 28, 2021, 4:19pm
#4
math.round() isn’t what I’m looking for, it needs to go to the nearest 0.5. So for example:

0.5 - 0.5
0.4 - 0.5
0.1 = 0
etc

Ex_Bla
(GroupHolder)
August 28, 2021, 4:21pm
#5
THANK YOU SO MUCH! Literally what I’ve been looking for, have a great day!

D0RYU
(nici)
August 28, 2021, 4:38pm
#6

MrMoled:

```
function SnapPosition(original, size)
local snapped = Vector3.new()
snapped = Vector3.new(
math.floor(original.X / size + 0.5) * size,
math.floor(original.Y / size + 0.5) * size,
math.floor(original.Z / size + 0.5) * size
)
return snapped
end
```

another way would be this

```
function SnapPosition(original, size)
return Vector3.new(
math.round(original.X / size) * size,
math.round(original.Y / size) * size,
math.round(original.Z / size) * size
)
end
```

don’t see why math.round isn’t used here