cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

How to adjust decimal places in a parameter

ANDERSON
2-Explorer

How to adjust decimal places in a parameter

The 0.015000 radius comes from a parameter. How do I adjust this so that it has fewer decimal places. I can't type anything else in the &MIN_RADIUS box (such as [.3]), and if I enter text manually it doesn't recognize that I'm trying to pull a parameter.

ACCEPTED SOLUTION

Accepted Solutions
psobejko
13-Aquamarine
(To:ANDERSON)

Yes, the problem is that your parameter is of type "Real Number", and the sketch text tool works better when displaying parameters of type "String".

And "converting" real numbers into strings in Creo is possible but difficult because PTC never provided the "RTOS" (Real to String) function.  They do give you the "ITOS" (integer to string) function, which can be manipulated to give you what you the result you want but you will have to write relations to do it.  Maybe you can find them on this new forum by searching for "RTOS".

 

This is one that works well for me:

RN = FLOOR((MIN_RADIUS+(5/10^(DEC_PLACES+1))),DEC_PLACES)

IF FLOOR(RN) == 0  
  MIN_RAD_STRING = "0."+EXTRACT(ITOS((RN-FLOOR(RN)+1)*10^(DEC_PLACES)),2,DEC_PLACES)
ELSE  
  MIN_RAD_STRING = ITOS(FLOOR(RN))+"."+EXTRACT(ITOS((RN-FLOOR(RN)+1)*10^(DEC_PLACES)),2,DEC_PLACES)  
ENDIF

Note:

MIN_RADIUS = the parameter that is of type REAL NUMBER

MIN_RAD_STRING = parameter of type STRING that is the rounded number

DEC_PLACES = parameter of type INTEGER which value specifies the # of decimal places in the produced MIN_RAD_STRING 

 

View solution in original post

6 REPLIES 6
psobejko
13-Aquamarine
(To:ANDERSON)

Yes, the problem is that your parameter is of type "Real Number", and the sketch text tool works better when displaying parameters of type "String".

And "converting" real numbers into strings in Creo is possible but difficult because PTC never provided the "RTOS" (Real to String) function.  They do give you the "ITOS" (integer to string) function, which can be manipulated to give you what you the result you want but you will have to write relations to do it.  Maybe you can find them on this new forum by searching for "RTOS".

 

This is one that works well for me:

RN = FLOOR((MIN_RADIUS+(5/10^(DEC_PLACES+1))),DEC_PLACES)

IF FLOOR(RN) == 0  
  MIN_RAD_STRING = "0."+EXTRACT(ITOS((RN-FLOOR(RN)+1)*10^(DEC_PLACES)),2,DEC_PLACES)
ELSE  
  MIN_RAD_STRING = ITOS(FLOOR(RN))+"."+EXTRACT(ITOS((RN-FLOOR(RN)+1)*10^(DEC_PLACES)),2,DEC_PLACES)  
ENDIF

Note:

MIN_RADIUS = the parameter that is of type REAL NUMBER

MIN_RAD_STRING = parameter of type STRING that is the rounded number

DEC_PLACES = parameter of type INTEGER which value specifies the # of decimal places in the produced MIN_RAD_STRING 

 

TheBU
5-Regular Member
(To:psobejko)

Hi psobejko,

 

So i found that a simplified version of your method still works:

instead of 

EXTRACT(ITOS((RN-FLOOR(RN)+1)*10^(DEC_PLACES)),2,DEC_PLACES)

you could just use  

ITOS((RN-FLOOR(RN))*10^(DEC_PLACES))

the syntax would than be:

RN = FLOOR((MIN_RADIUS+(5/10^(DEC_PLACES+1))),DEC_PLACES)

IF FLOOR(RN) == 0  
  MIN_RAD_STRING = "0."+ITOS((RN-FLOOR(RN))*10^(DEC_PLACES))
ELSE  
  MIN_RAD_STRING = ITOS(FLOOR(RN))+"."+ITOS((RN-FLOOR(RN))*10^(DEC_PLACES))  
ENDIF

The EXTRACT function just extracted the values behind the comma (AKA decimals) as a string, which is what ITOS ((RN-FLOOR(RN))*10^(DEC_PLACES)) will do also.

 

For EXAMPLE:

 

RN=2,594956

DEC_PLACES=2

 

RN-FLOOR(RN) equals a real number with only decimals: 0,594956

 

Multiplying that number by 10^(DEC_PLACES) will give you a real number with x=(DEC_PLACES) decimals "promoted" to whole numbers: 59,4956

 

Using ITOS will extract only the WHOLE numbers, which is what we want:

ITOS(RN-FLOOR(RN)*10^(DEC_PLACES))=59

I've used relations to do this also, but sometimes the number I want is a negative number, making the floor function provide unexpected results ( floor ( -5.1 ) = -6, etc). The code I need to use is more complicated to handle this possibility. Also, I've noticed that ITOS rounds the value it is using, for example ITOS ( 12.6 ) = "13", so I don't need to "adjust" the integer I'm converting to get a rounded value.

 

--- Variables ---

realnum : the real number that will be represented by the string

stringer : the resultant string

numplaces : the number of decimal places in the final result

 

--- Relations Code ---

if realnum < 0
  stringer = "-" + ITOS ( floor ( ABS ( realnum ) ) )
else
  stringer = ITOS ( floor ( realnum ) )
endif
stringer = stringer + "."
stringer = stringer + EXTRACT ( ITOS ( 10^numplaces * ( 1 + ABS ( realnum ) - floor ( ABS ( realnum ) ) ) ), 2, numplaces )

 

Kind of fun if you're doing this for one number, but this stuff gets tedious if you have a lot of numbers you want to use in notes and such.

bbrejcha
14-Alexandrite
(To:KenFarley)

I want to do the same... except the parameter is in the weld symbol.  45.000°   What I want is 45°    Ill mess around w/ your relations techniqe.  I like it BTW  but those darn SW users are guna laugh.   

 

 

Bart Brejcha

Design-engine.com

Annotate>Format>Decimal Places enter number of decimal places and select the parameter.  You might have to click 2 or 3 times to select the parameter.

Param.JPG

 

As displayed in drawing after changing decimal places:

Test.JPG

hadfiej23
4-Participant
(To:Pieface)

I noticed that there is a quick way to change/add decimal places in a real number parameter by using text "&PARAMETER[.3]" in the drawing.  The number in brackets is the number of decimal places you get (in this case, 3).  If you need only 1 decimal place, for instance, just replace the .3 in the brackets with .1.

 

-Jessica Hadfield 

Announcements
NEW Creo+ Topics: Real-time Collaboration


Top Tags