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.


COE Community News

Follow COE on

COE DISCUSSION FORUM
Rounding a parameter
Last Post 11 Nov 2009 07:16 PM by FIVEAPPLERUSH. 9 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
DPATTERSON
New Member
New Member
Posts:22

--
27 Oct 2009 01:08 PM  

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

CLIFFJOHNSON
Advanced Member
Advanced Member
Posts:516
Avatar

--
27 Oct 2009 01:42 PM  

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

MBERRY
Basic Member
Basic Member
Posts:470

--
27 Oct 2009 01:43 PM  
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
DPATTERSON
New Member
New Member
Posts:22

--
27 Oct 2009 02:46 PM  
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
New Member
New Member
Posts:0

--
27 Oct 2009 02:46 PM  
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
Basic Member
Basic Member
Posts:470

--
27 Oct 2009 02:55 PM  
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
CLIFFJOHNSON
Advanced Member
Advanced Member
Posts:516
Avatar

--
27 Oct 2009 06:56 PM  
The round function can be used directly on a length parameter without playing games with the units.
MBERRY
Basic Member
Basic Member
Posts:470

--
27 Oct 2009 07:06 PM  
Hey Cliff, can you give example?
CLIFFJOHNSON
Advanced Member
Advanced Member
Posts:516
Avatar

--
28 Oct 2009 01:10 AM  

Example...

MBERRY
Basic Member
Basic Member
Posts:470

--
28 Oct 2009 04:17 PM  

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

FIVEAPPLERUSH
New Member
New Member
Posts:1

--
11 Nov 2009 07: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