Greatings whole community,
have a simply question: How to convert real number to string, including decimal places? String value CAN NOT be rounded.
Example:
d150 = 1.5 (it is real number dimmension)
string_value=1.5
Have found some topics about this, but no simply solution.
l´m trying to use exctract and itos function, but my design strat to be complicated.
Maybe in creo 5.0 has been added some better function or someone was god-lighted up and got an idea for Nobel price
Thanks in any advice...
Regards
Solved! Go to Solution.
Relations functions haven't been changed since they were introduced. In my past conversations with PTC their position as been that while complicated you can do nearly everything with the existing relation functions. There are numerous ideas to add additional functions to make things easier but none have been implemented.
If you haven't stumbled on it already you might want to try @TomU's method here:
https://community.ptc.com/t5/Simulation/Converting-Real-Numbers-to-Strings/m-p/189624
He links to some official PTC examples as well.
Relations functions haven't been changed since they were introduced. In my past conversations with PTC their position as been that while complicated you can do nearly everything with the existing relation functions. There are numerous ideas to add additional functions to make things easier but none have been implemented.
If you haven't stumbled on it already you might want to try @TomU's method here:
https://community.ptc.com/t5/Simulation/Converting-Real-Numbers-to-Strings/m-p/189624
He links to some official PTC examples as well.
Hi @Chris3 and @KenFarley
thanks for links, l will study it later.
Wish you both happy day and many thanks to you...
Despite years and years of needing it, a simple "real to string" function has never been added to Pro/E or subsequently, Creo. A bit of programming that has been handled for decades (I even remember doing so in assembly language back in the olden times) is not available.
Anyway, here's my bit of code to approach this.
/* /* Convert a real number into a string. /* numReal = the number to convert /* strResult = the resulting string /* numDigits = integer for how many digits after the decimal you want. /* strResult = ITOS ( floor ( abs ( numReal ) ) ) + "." IF abs( numReal ) < 1.0 strResult = "0." ENDIF strResult = strResult + EXTRACT ( ITOS ( floor ( 10^numDigits * ( 1 + abs ( numReal ) - floor ( abs ( numReal ))))),2,numDigits ) IF numReal < 0.0 strResult = "-" + strResult ENDIF
There are lots of other approaches to this problem. Without a built-in function to do the conversion, you end up with a large amount of relation code if you need to do this for a lot of numbers.
Note that the "rounding avoidance" is done by the "floor" applied to the shifted number before the ITOS function call within the EXTRACT function call. It truncates all the digits after the decimal.
Hi @KenFarley
in result l´m using your solution.
Following row is pure logical and mathematical beauty:
strResult = strResult + EXTRACT ( ITOS ( floor ( 10^numDigits * ( 1 + abs ( numReal ) - floor ( abs ( numReal ))))),2,numDigits )
Thanks to pople like you
Have nice day
Regards
Hello,
I've requested this option back in 2012, still waiting. You can vote on this and maybe someday we'll see a simple solution from PTC:
https://community.ptc.com/t5/Creo-Parametric-Ideas/Real-to-String-in-Relations/idi-p/465330