Round to the nearest decimal (say nearest .125)

Maybe an easy one, but I can seem to be able to find a way to round a decimal number to the nearest specified decimal amount.

For example, I want to round this data list to the nearest 0.125 (1/8"). Any thoughts?

Pufferfish plug-in has a feature named Round To Nearest.

1 Like

Which I guess does something like this:


using the Expression component:


All good solutions, thanks to all.

Round(x, y) works too!

X is the numbers you want to round and y is the decimal places, you can plug in a slider and change it or directly type 8

Round(x, 8).

That’s something different than the original question.

Oh you are right!
In that case you can use this expression as David suggested:
f=rounding factor, v=values

You could use the example here that pops that expression into a little userobject/cluster:

I just updated Pufferfish and the V2.1 has a “Round To Factor” component for this.

1 Like

Just also added a “Round To Decimal Place” component in the new Pufferfish V2.2


Is there a way to no suppress trailing 0’s so the specified decimal places (say 3 deep) are preserved? I’m seeing numbers that do round to a whole number clip so I’m getting 7 instead of 7.000 - thoughts on how to adjust this formatting?

update : found this thread that addresses my needs -

essentially using an Expression component with Format("{0:0.000}",x) will get you to round off to 3 decimal places and not suppress 0’s. Cheers!

There is also settings in GH for how many decimals you see in File>Preferences>Formatting