COE Store (large)

Welcome to the COE Discussion Forums! 

 

To participate in the discussion forum, you must be logged in to the website.  If you forget your login information, please contact COE Headquarters at coe@coe.org or (800) 263-2255.

If you are new to the COE Discussion Forum and would like to participate, please register.


 

Follow COE on

COE DISCUSSION FORUM
Rounding a parameter
Last Post 11 Nov 2009 01:16 PM by FIVEAPPLERUSH. 9 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
DPATTERSON
Occasional Poster
Occasional Poster
Posts:22


--
27 Oct 2009 07:08 AM  

I need a parameter to be 2 decimal places regardless of the decimals I have set in tools  > options.  Any ideas?

CLIFFJOHNSON
500+ Poster
500+ Poster
Posts:553
Avatar


--
27 Oct 2009 07:42 AM  

There is a "round" function that can be used in formulas for this purpose.



MBERRY
500+ Poster
500+ Poster
Posts:584


--
27 Oct 2009 07:43 AM  
It kind of depends on the type of parameter. I don't think real params have a setting for number of dec plcs, so you might want to make a real param then apply a formula like this,

Real.1 = round(`Length.1`, "mm", 2)

You can do the same thing with other types of parameters, but they have settings to control the number of decimal places so it could be a problem if you require 2 and the setting says 1 ...in this case you will get 1.

-Mike
Increase your CATIA V5 programming skills
v5vb.wordpress.com
DPATTERSON
Occasional Poster
Occasional Poster
Posts:22


--
27 Oct 2009 08:46 AM  
works OK, but it seems I have to cheat this everytime I do it.

in my formula Real.1 = round(`Length.1`, "mm", 2) , I have to add *1000, if I want "mm" and *1000/25.4, if I want "in"
DPATTERSON
Occasional Poster
Occasional Poster
Posts:0


--
27 Oct 2009 08:46 AM  
works OK, but it seems I have to cheat this everytime I do it.

in my formula Real.1 = round(`Length.1`, "mm", 2) , I have to add *1000, if I want "mm" and *1000/25.4, if I want "in"
MBERRY
500+ Poster
500+ Poster
Posts:584


--
27 Oct 2009 08:55 AM  
Yeah, I forgot that the round function expects a real parameter not length, so technically you should do this,

Real.1 = round(`Length.1`/1mm, "", 2)

-Mike
Increase your CATIA V5 programming skills
v5vb.wordpress.com
CLIFFJOHNSON
500+ Poster
500+ Poster
Posts:553
Avatar


--
27 Oct 2009 12:56 PM  
The round function can be used directly on a length parameter without playing games with the units.
MBERRY
500+ Poster
500+ Poster
Posts:584


--
27 Oct 2009 01:06 PM  
Hey Cliff, can you give example?
Increase your CATIA V5 programming skills
v5vb.wordpress.com
CLIFFJOHNSON
500+ Poster
500+ Poster
Posts:553
Avatar


--
27 Oct 2009 07:10 PM  

Example...



MBERRY
500+ Poster
500+ Poster
Posts:584


--
28 Oct 2009 10:17 AM  

Cliff - I see what you were saying...same as my earlier post but you are suggesting to use a length for the formula output.  I was thinking maybe you had some other trick in mind.  I had suggested to use a real instead of length because it seems like the only way to guarantee a given # of decimal plcs.  Like in this example my units setting only allows 1 decimal place, so I only get one even though the formula returns 2...

 -Mike



Increase your CATIA V5 programming skills
v5vb.wordpress.com
FIVEAPPLERUSH
Occasional Poster
Occasional Poster
Posts:1


--
11 Nov 2009 01:16 PM  

Hi guys -  Was the question in regard to controlling the display precision (number of digits) of the rounded number?  If so - how about converting to string and parsing.  I'm doing this in a rule i'm working on.  Note:  The caveat in my case is that I had to output the values as string to prevent the stripping of the extra zeros - but that was fine as mine are input values for a drawing (besides, numeric strings can later convert back to real with no problem).  Here's an excerpt of my rule which successfuly rounds, and then displays length values - hope it helps:

Danny

 

   /* CUT HERE =======================================*/
   PtCoord = 1.5in   /* TEMPORARY - REMOVE!!!! */
   
   
   
   RoundedString = ToString( round( PtCoord /.0254 , "", DesiredPrecision )) /* Multiplying Length by 1 converts to required input type of Real */
   DecimalIndex =  RoundedString ->Search( "." )    /* Locate the index of the decimal in the number - add one if necessary */
    
   if DecimalIndex == -1      /* Add a decimal if necessary */
   {
    RoundedString = RoundedString + "."
    DecimalIndex = RoundedString ->Search( "." )
   }
   
   DigitsAfterDecimal = ( RoundedString .Length()) - ( DecimalIndex ) -1  /*  Determine how many zeros must be added and add them  */
   ZerosToAdd = DesiredPrecision - DigitsAfterDecimal
   
   OutputString  = RoundedString
   Zeros = 1
   for Zeros while Zeros <= ZerosToAdd { OutputString = OutputString + "0" }
   
   OutputParmName = OutputsNameList ->GetItem( i )   /*  Get the output string param and set its value  */
   StringsFeatureIN ->SetAttributeString( OutputParmName , OutputString  )

   /* CUT HERE =======================================*/

 

You are not authorized to post a reply.

Active Forums 4.1