DPATTERSON
 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 Posts:516

 |
| 27 Oct 2009 01:42 PM |
|
There is a "round" function that can be used in formulas for this purpose. |
|
|
|
|
MBERRY
 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 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 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 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 Posts:516

 |
| 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 Posts:470
 |
| 27 Oct 2009 07:06 PM |
|
Hey Cliff, can you give example? |
|
|
|
|
CLIFFJOHNSON
 Advanced Member Posts:516

 |
|
MBERRY
 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 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 =======================================*/
|
|
|
|
|