# 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:

3 Likes

using the `Expression` component:

3 Likes

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*Cint(v/f)
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

2 Likes

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?

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!