Rounding float to nearest multiple of a set float?

Hi, I’m trying to create a movable vector in blueprint that snaps to multiples of a float that I have set in a veritable. My problem however is that I don’t know how to clamp the vectors x, y, z values to multiples of the float.

Any help would be much appreciated, thank you.

Something like this:

Idea is to DIVIDE by your step size , then multiply by it but skipping remainder part.

2 Likes

exactly what I needed. Thank you for your help

wow thanks :smiley:

This is a good, but slightly flawed approach as it always rounds down so a value of 19.9 with a step of 1.0 will become 19.0 instead of 20.0.

Goodnews is it’s easy to fix by Rounding the remainder and adding it to the result of the multiplication.

Update: I realized my reply only worked well for step values <= 1.0 To that end I’ve added a second variant.

1 Like