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.

round( ) function

tim_ashbytim_ashby Member Posts: 3 ✭✭
Is it possible to specify the number of decimal places that the round( ) function rounds to? The standard Excel format of round(number, dp) doesn't seem to work. Alternatively, is there a workaround?. Thanks!

Best Answer

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,688
    edited June 2016 Answer ✓
    round(value * 100) / 100 should do the trick (to 2 dp)
    Senior Director, Technical Services, EMEAI

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,688
    edited June 2016 Answer ✓
    round(value * 100) / 100 should do the trick (to 2 dp)
    Senior Director, Technical Services, EMEAI
  • patrick_farleypatrick_farley Member Posts: 37 ✭✭
    round() as now a value and a multiple.
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @patrick_farley

    round(value, .01) is probably what you are looking for rather than round(value, 2):
    https://cad.onshape.com/FsDoc/library.html#round--
    Jake Rosenfeld - Modeling Team
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    You'll notice also in that documentation that value and multiple can also both be valueWithUnits, and the result will come out as a plain number (whose "unit" corresponds to the "multiple")
    Jake Rosenfeld - Modeling Team
  • leon_tullingleon_tulling Member Posts: 7
    edited June 21
    I'm trying to use the solution above, but I keep getting errors (Function Round with 2 argument(s) not found). Any idea what can go wrong here?

    Part of my code
    var es = definition["segment" ~ i] / millimeter;
    partNumber ~= toString(round(es, .01));
    Creative Technician Mechatronics | Freelance Engineer
    www.leontulling.nl
  • _anton_anton Member, Onshape Employees Posts: 410
    @leon_tulling You're likely on a very old version of the FS standard library. The two-argument function was introduced around six years ago.
  • Eric_WongEric_Wong Member Posts: 23 PRO
    @leon_tulling roundToPrecision() is the new way to do this. See here https://cad.onshape.com/FsDoc/library.html 

Sign In or Register to comment.