Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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 values to whole numbers in text
So I'm building a project that I want to be fully scalable for the user, and want to display the final output size on a flat surface.
I got this working by making a textbox and adding ""X" ~ toString(#BED_X/mm) ~ "mm"" and this displays the variable as it should.
However, if I scale the project by anything other than 50mm increments, it changes from "xxx mm" to "xxx.xxxxxxxxxxxxxx mm"
Ive chased around my assembly and parts, and theres nothing I can find that would add that value.
Is there a way for me to just round the number in the textbox to not have decimals?
This is my issue
If I set my frame size to a 50mm increment number, it works just fine
Answers
You can use the round() function to round your numbers. Or you may need to use the roundToPrecision() function if you need a specific number of decimals. However, your units will be in meters, since Onshape uses Meters behind the scenes. It is possible to convert them with a multiplier constant, but it may simply be easiest to use a custom feature to help.
Here is a custom feature I made to specifically convert variables to string and specify units and rounding:
Convert to String: https://cad.onshape.com/documents/19dacc01596e7c326bbfb137/w/0567dd7ffac5327836c9bb93/e/cd2c8c…
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Thank you so much! That's exactly what I needed.