Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Rounding values

Luc_ROLLANDLuc_ROLLAND Member Posts: 6
Hello !
I try rounding calculations,
PosMin=2.9cm
PosMax=5.5cm 
#PosMin+(((#PosMax-#PosMin)/5)*2)
return 3.94cm
but I need mathematical rounding, so I write :roundToPrecision(#PosMin+(((#PosMax-#PosMin)/5)*2),1)
or
roundToPrecision((#PosMin+(((#PosMax-#PosMin)/5)*2)),1)
or
roundToPrecision((#PosMin+(((#PosMax-#PosMin)/5)*2)),1))cm
(
I hope 3.9cm
but I obtain an error !
(as with some others variants).

I don't understand where I'm wrong, but I'm newbee with OnShape ...
Please help me.

Luc

Best Answer

  • Matt_ShieldsMatt_Shields Member, Onshape Employees Posts: 415
    Answer ✓
    Or if PostMin and PostMax have to have units, this would work.

    roundToPrecision(#PosMin/(cm)+(#PosMax-#PosMin)/(5 cm)*2,1)cm

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,686
    edited May 2023
    roundToPrecision only works with numbers, not ValueWithUnits, so you should use:

    PosMin=2.9
    PosMax=5.5
    roundToPrecision(#PosMin+((#PosMax-#PosMin)/5)*2,1) * cm
    Senior Director, Technical Services, EMEAI
  • Matt_ShieldsMatt_Shields Member, Onshape Employees Posts: 415
    Answer ✓
    Or if PostMin and PostMax have to have units, this would work.

    roundToPrecision(#PosMin/(cm)+(#PosMax-#PosMin)/(5 cm)*2,1)cm

  • Luc_ROLLANDLuc_ROLLAND Member Posts: 6
    A little bit complex.
    Many thanks.
Sign In or Register to comment.