Skip to main content
Ayush Bakshi
Inspiring
December 4, 2024
Answered

How to convert a float input into a stepped value of choice?

  • December 4, 2024
  • 1 reply
  • 569 views

In super short, I want to do this ↓

Calculator

And I've tried these:

LINK 1 

LINK 2


I want to give user a float slider (to move something in X and Y) but the result should be a multiple of 1/32 (let's say).

 

The approaches I tried are not giving me the 'Stepped' result but smooth continous values.

 

Happy holidays to the US folks! 

Thanks!

This topic has been closed for replies.
Correct answer Marco Vitale

Hey Ayush,

Great task, I'll give you an outline of how this would work.

Lets say you want a float to be a multiple of 1/32

1. Multiply the float with 32, so you have a floating point value between 0 and 32

2. Use the floor function on the result or round the result to the nearest integer value (depending on what you want to achieve)

3. Divide the rounded value by 32 to get a stepped value between 0 and 1 with a distance of 1/32

 

If you have any arbitrary value which is not expressable by a fraction, let's say you want values to be a multiple of 0.0317 then just divide the input float by this value this gives you a range between 0 and 1/0.0317 floor or round the result and multiply it by 0.0317 and you have a stepped value with multiples of 0.0317.

 

I hope this helps, stay healthy and creative Marco 

1 reply

Marco VitaleCommunity ExpertCorrect answer
Community Expert
December 4, 2024

Hey Ayush,

Great task, I'll give you an outline of how this would work.

Lets say you want a float to be a multiple of 1/32

1. Multiply the float with 32, so you have a floating point value between 0 and 32

2. Use the floor function on the result or round the result to the nearest integer value (depending on what you want to achieve)

3. Divide the rounded value by 32 to get a stepped value between 0 and 1 with a distance of 1/32

 

If you have any arbitrary value which is not expressable by a fraction, let's say you want values to be a multiple of 0.0317 then just divide the input float by this value this gives you a range between 0 and 1/0.0317 floor or round the result and multiply it by 0.0317 and you have a stepped value with multiples of 0.0317.

 

I hope this helps, stay healthy and creative Marco 

Ayush Bakshi
Inspiring
December 5, 2024

That worked. Thanks! Guess I was overcomplicating stuff 😛

One pet peeve with the Safe Transform node though, for some reason it's giving wonky result at (0,0).
For now I'll just add 0.01