latest

Operators

Round To Factor

Round a number to a multiplication factor.

ID

math-operators-round-to-factor

Name

Round To Factor

Group

Operators

Package

Math

Keywords

round
factor
multiplication
nearest
floor
ceiling

Operators

Trigonometric

Tools

Constants

Round To Factor

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.

Problem Addressed

Often, calculations or measurements result in numbers that are too precise or don't align with practical constraints. This node helps by:

  • Snapping to increments: Ensuring values conform to specific steps (e.g., multiples of 0.5, 10, 100).
  • Simplifying values: Reducing precision in a controlled manner.
  • Enforcing design rules: Aligning numbers with manufacturing tolerances or modular sizes.

How It Works

The node takes a Number X, a Factor, and a Round Type:

  • Number X: The input number you want to round.
  • Factor: The value whose multiples you want to round to. For example, if Factor is 5, the number will be rounded to the nearest multiple of 5 (e.g., 0, 5, 10, 15).
  • 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: The result of the rounding operation.
  • Difference: The value of Rounded - Number X.
  • Multiplier R: How many times Factor fits into the Rounded number (Rounded / Factor).
  • Multiplier X: How many times Factor fits into the original Number X (Number X / Factor). This can be a fractional value.

Examples

  1. Rounding to the nearest whole number (Factor = 1):

    • Number X: 7.8
    • Factor: 1
    • Round Type: 0 (Nearest)
    • Rounded: 8
    • Difference: 0.2
    • Multiplier R: 8
    • Multiplier X: 7.8
  2. Rounding a measurement down to the nearest 0.25 unit:

    • Number X: 10.6
    • Factor: 0.25
    • Round Type: 1 (Floor)
    • Rounded: 10.5
    • Difference: -0.1
    • Multiplier R: 42 (10.5 / 0.25)
    • Multiplier X: 42.4 (10.6 / 0.25)
  3. Rounding a price up to the next multiple of 10:

    • Number X: 123
    • Factor: 10
    • Round Type: 2 (Ceiling)
    • Rounded: 130
    • Difference: 7
    • Multiplier R: 13
    • Multiplier X: 12.3
  4. Working with negative numbers (Nearest):

    • Number X: -7.2
    • Factor: 2
    • Round Type: 0 (Nearest)
      • -7.2 / 2 = -3.6. Math.round(-3.6) = -4. -4 * 2 = -8.
    • Rounded: -8
    • Difference: -0.8
    • Multiplier R: -4
    • Multiplier X: -3.6

Inputs

NameTypeDescriptionDefault 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 = Ceiling0

Outputs

NameTypeDescription
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