Tom,
You're lurking the forums for threads similar to this one, pointing out the stuff posted here and there is wrong! That's kinda funny
Actually, it's great to see someone taking the time to tell these are all off. To show that we seriously need a rtos() function.
I use similar relations posted in the beginning of this thread, but always with just two dec places. It does the job for me except when the dimension is smaller than 1, then it just outputs 0, but that's propably because of other error in my code.
Here is my attempt at something better: Converting Real Numbers to Strings
Simply adding number format could solve it ?
&MASS:FID_9.1 is the parameter included in the note
Mass: &MASS:FID_9.1: gr -> Mass : 125.326 gr -> print 3 decimal (default)
Mass: &MASS:FID_9:1[.1] gr -> Mass : 125.3 gr only -> print 1 decimal only.
This is not for drawings, it's for getting the real number converted to a string for use as a model parameter. For example, if you want a DESCRIPTION parameter (in the model!) to include multiple three place dimensions, you have to manually do this conversion before building the parameter text.
/* Real Numbers (map to actual dimensions)
L1 = 1.25
L2 = 2.50
L3 = 3.00/* String Output - No Leading Zero, Two Decimal Places
L1_STRING = ITOS(FLOOR(L1+.005))+"."+EXTRACT(ITOS(((FLOOR((L1+.005),2))-FLOOR(FLOOR((L1+.005),2))+1)*100),2,2)
L2_STRING = ITOS(FLOOR(L2+.005))+"."+EXTRACT(ITOS(((FLOOR((L2+.005),2))-FLOOR(FLOOR((L2+.005),2))+1)*100),2,2)
L3_STRING = ITOS(FLOOR(L3+.005))+"."+EXTRACT(ITOS(((FLOOR((L3+.005),2))-FLOOR(FLOOR((L3+.005),2))+1)*100),2,2)/* Generate DESCRIPTION parameter
DESCRIPTION = L1_STRING + " x " + L2_STRING + " x " + L3_STRING
Sorry, just realized I replied to a very old post. The answer you provided was acceptable since the OP was using a note.
Ho Tom,
Loved your write up on this. As I am a little programming deficient .... How would change the output on this to 3 decimal places? I have been playing with it a bit but not getting the result I want. Any help would be great. Thanks,
Matthew
@TomU wrote:
This is not for drawings, it's for getting the real number converted to a string for use as a model parameter. For example, if you want a DESCRIPTION parameter (in the model!) to include multiple three place dimensions, you have to manually do this conversion before building the parameter text.
/* Real Numbers (map to actual dimensions)
L1 = 1.25
L2 = 2.50
L3 = 3.00
/* String Output - No Leading Zero, Two Decimal Places
L1_STRING = ITOS(FLOOR(L1+.005))+"."+EXTRACT(ITOS(((FLOOR((L1+.005),2))-FLOOR(FLOOR((L1+.005),2))+1)*100),2,2)
L2_STRING = ITOS(FLOOR(L2+.005))+"."+EXTRACT(ITOS(((FLOOR((L2+.005),2))-FLOOR(FLOOR((L2+.005),2))+1)*100),2,2)
L3_STRING = ITOS(FLOOR(L3+.005))+"."+EXTRACT(ITOS(((FLOOR((L3+.005),2))-FLOOR(FLOOR((L3+.005),2))+1)*100),2,2)
/* Generate DESCRIPTION parameter
DESCRIPTION = L1_STRING + " x " + L2_STRING + " x " + L3_STRING
/* String Output - No Leading Zero, Three Decimal Places L1_STRING = ITOS(FLOOR(L1+.0005))+"."+EXTRACT(ITOS(((FLOOR((L1+.0005),3))-FLOOR(FLOOR((L1+.0005),3))+1)*1000),2,3) L2_STRING = ITOS(FLOOR(L2+.0005))+"."+EXTRACT(ITOS(((FLOOR((L2+.0005),3))-FLOOR(FLOOR((L2+.0005),3))+1)*1000),2,3) L3_STRING = ITOS(FLOOR(L3+.0005))+"."+EXTRACT(ITOS(((FLOOR((L3+.0005),3))-FLOOR(FLOOR((L3+.0005),3))+1)*1000),2,3)
By the way, the original post about this formula is located here:
https://community.ptc.com/t5/Creo-Modeling-Questions/Converting-Real-Numbers-to-Strings/m-p/189624
(Edited 10/2/2017 to correct error.)
Yeah.. just figured that out just before I read this. Sorry to bother you but thanks for you reply.
Thanks, Matthew
Hi Tom,
I hate to bug you again over this but I'm having a smal issue and I'm not sure whats driving it. I"m using these lines of code to report a parameter.. in this case "LENGTH". It is reporting a number for me but it's not reporting the correct value. My actual value is 29.856 but it is reporting 29.186.What am I missing to make it report the actual true value of my LENGTH parameter? Can I email you directly??
There was a mistake in the post above. I have corrected it. Sorry about that.