Fine tune the results of your equations

Article by Alin Vargatu, CSWE updated June 27, 2011

Article

What do you do when you need to find a quick answer to a SolidWorks related question?

I, for one, go first to the help file, then to the SolidWorks Knowledgebase and in the end to one of my more experienced colleagues (you know them: Wayne, Rob, Joe, Chris, Andrew, Scott, Matt, Adam). This approach insures a 99.9% success rate.

But what do you do if it’s week-end, the weather outside is gorgeous and Wayne, Rob, Joe, Chris, Andrew, Scott, Matt and Adam are all having fun at the beach? Whom can you ask for help?

You can ask the world, that’s who. The SolidWorks community, to be more precise. The citizens of these fora never go to the beach and I suspect they never sleep. You will always find somebody ready to answer your questions and to provide solutions – in less time it took me to write this post. Most of the times, a question generates a whole brainstorming session which results in multiple solutions.

Only last week-end, one of the forum’s gurus, Deepak Gupta, asked a very interesting question. Now you should know that Deepak is usually the one providing solutions to other people’s problems, so whenever he asks a question, you can bet is a tough one.

He asked this question Saturday afternoon and by the end of the week-end, no less than 3 solutions were suggested. What makes this outcome even more interesting, is the fact that (to the best of my knowledge) none of these solutions can be found anywhere in the SolidWorks documentation.

Deepak also came with the perfect example for when such a “rounding” might be needed. Let’s say your file units are set to imperial (the mass is expressed in pounds) and you need to list the mass in kilograms in a drawing.

The equation would be: 

“Mass_in_lb”=”SW-Mass”/2.2

You will notice that the result of the SolidWorks equation is 454.545. What if you need a 2 digits precision? Changing the settings in the Tools/Options/Document Properties/Units/Decimals does not affect the precision of the equation result.

Solution #1 from Bill Hamze :

You can use the Round function in the equation body. For 2 digits precision the equation would be:

“Mass_in_lb”=round(“SW-Mass”/2.2, 2)

 



Solution #2 from WayneMatus :

You can use the Format command from VBA in the equation body. For 2 digits precision the equation would be:

”Mass_in_lb”=Format( “SW-Mass”/2.2,”#.##”)

 

Solution #3:

Write your own rounding function. To make things easier to understand, 2 equations were created:

“Precision”= 2

“Mass_in_lb”= Int(“SW-Mass”/2.2*10 ^ “Precision”+.5)/10^”Precision”

 

What do you think? Can you suggest a fourth solution?

Related Links

Get Certified SOLIDWORKS Services from Javelin

Javelin Experts can help you to:

Posts related to 'Fine tune the results of your equations'

Alin Vargatu, CSWE

Alin is a SOLIDWORKS Elite Applications Engineer and an avid contributor to the SOLIDWORKS Community. Alin has presented multiple times at SOLIDWORKS World, Technical Summits, and User Group Meetings, while being very active on the SOLIDWORKS Forum.