Round a number to a multiplication factor.
ID
math-operators-round-to-factor
Name
Round To Factor
Group
Operators
Package
Math
Keywords
This node adjusts a number (Number X
) to a multiple of a specified Factor
. You can control the rounding behavior using Round Type
. This is useful when you need values to snap to predefined increments or multiples.
For example, if you are designing something that can only be manufactured in lengths that are multiples of 5mm, you can use this node to take any given length and round it to the nearest 5mm increment. Or, if you're working with currency and need to round to the nearest $0.25, this node can perform that calculation.
Often, calculations or measurements result in numbers that are too precise or don't align with practical constraints. This node helps by:
The node takes a Number X
, a Factor
, and a Round Type
:
0
(Nearest): Rounds Number X
to the closest multiple of Factor
. If Number X
is exactly halfway between two multiples, it rounds to the multiple further from zero (standard Math.round
behavior for the division Number X / Factor
).1
(Floor): Rounds Number X
down to the nearest multiple of Factor
that is less than or equal to Number X
.2
(Ceiling): Rounds Number X
up to the nearest multiple of Factor
that is greater than or equal to Number X
.The node outputs:
Rounded
- Number X
.Factor
fits into the Rounded
number (Rounded / Factor
).Factor
fits into the original Number X
(Number X / Factor
). This can be a fractional value.Rounding to the nearest whole number (Factor = 1):
7.8
1
0
(Nearest)8
0.2
8
7.8
Rounding a measurement down to the nearest 0.25 unit:
10.6
0.25
1
(Floor)10.5
-0.1
42
(10.5 / 0.25)42.4
(10.6 / 0.25)Rounding a price up to the next multiple of 10:
123
10
2
(Ceiling)130
7
13
12.3
Working with negative numbers (Nearest):
-7.2
2
0
(Nearest)
-7.2 / 2 = -3.6
. Math.round(-3.6) = -4
. -4 * 2 = -8
.-8
-0.8
-4
-3.6
Inputs
Name | Type | Description | Default Value |
---|---|---|---|
x | Number | Number to round | |
factor | Number | Multiplication factor to round to | |
roundType | Number | Determines how the number is rounded 0 = Nearest 1 = Floor 2 = Ceiling | 0 |
Outputs
Name | Type | Description |
---|---|---|
rounded | Number | Resulting rounded number |
difference | Number | Difference between rounded and input x |
multiplierR | Number | Number of times factor fits into rounded number |
multiplierX | Number | Number of times factor fits into input number x |