Skip to main content
8-Gravel
February 7, 2025
Solved

&Parameter - String to [.X] decimal places??

  • February 7, 2025
  • 1 reply
  • 1226 views

Hi,


I have a situation where I need to express a number to 8 decimal places in a drawing. I have created a parameter in the model as a string due to the number of digits in the raw number.


Unfortunately when attempting in the standard approach in the drawing [.8] does not work after the &parameter, is there another syntax I need to use with this not being a real number?


The number is: 0.00654322641148869


I cannot enter the parameter as a real number due to the precision limitation on these values, hence using string.


Hopefully someone can guide me in the right direction.

Best answer by KenFarley

To try something, I defined two parameters, "numRaw" a real number, and "numRounded" a STRING.

The following relations assigned the raw value and then used it to build a string to represent your desired result.

numraw = 0.00654322641148869
IF numraw < 1.0
 numrounded = "0."
ELSE
 numrounds = ITOS ( floor ( numraw ) ) + "."
ENDIF
numrounded = numrounded + EXTRACT ( ITOS ( 10^8* ( 1 + numraw - floor ( numraw ) ) ), 2, 8 )

The ITOS function does an inherent rounding when used, or you could add specific calculations to round the number in whatever explicit manner you wish.

Parameters might look like they aren't using enough precision, but it's more a matter of what they are showing, not what they are holding. It's kind of like when you enter a number in an Excel cell - it might look like 2.556, but the actual value stored is 2.555789762 or whatever. I'm not sure what the actual decimal place limitation in Creo is, but it's definitely more places than just 8.

1 reply

16-Pearl
February 7, 2025

Hi @IE_1 ,

 

Unfortunately, the [.#] notation for limiting the number of decimal digits is not recognized in a string type parameter

I think we need to use some additional relation functions like extract

    

extract(string, position, length)

for example:

test="0.1234567890123456789"
limit=extract(test,1,(search(test,".")+8))

this sets the parameter TEST to the string value, then extracts from that parameter, starting from character #1 through 8 more characters from the position of the "."

 

An example for removing the lead 0 for the same test parameter would be 

limit=extract(test,search(test,"."),9)

 

Hope this helps!

Mike

IE_18-GravelAuthor
8-Gravel
February 7, 2025

Thanks Mike, in my drawing what would I be calling up?  &............

IE_18-GravelAuthor
8-Gravel
February 7, 2025

I've worked it out, thanks