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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

How To: Format a real number relation in a note?

TomD.inPDX
17-Peridot

How To: Format a real number relation in a note?

I have a real number variable and I want to represent this in a note with a limited number of decimal places.

The default decimal places is 3 in the part file and that is what I want. The note I want needs to be limited to 1 decimal place.

Since this is not a "dimension", I cannot edit the number of decimal places in properties.

I can set the decimal places in the "options" of the measure:distance dialog (for instance) but the relation only follows the units set in options of a saved measure, not the decimal places set in the options.

Creo 2.0

thanks

39 REPLIES 39
James62
10-Marble
(To:TomU)

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.

TomU
23-Emerald IV
(To:James62)

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.

TomU
23-Emerald IV
(To:pperrin)

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

TomU
23-Emerald IV
(To:TomU)

Sorry, just realized I replied to a very old post.    The answer you provided was acceptable since the OP was using a note.

mbuchholtz
4-Participant
(To:TomU)


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


 

TomU
23-Emerald IV
(To:mbuchholtz)

/* 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.)

mbuchholtz
4-Participant
(To:TomU)

Yeah.. just figured that out just before I read this. Sorry to bother you but thanks for you reply.

 

Thanks, Matthew

mbuchholtz
4-Participant
(To:TomU)

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??

TomU
23-Emerald IV
(To:mbuchholtz)

There was a mistake in the post above.  I have corrected it.  Sorry about that.

Top Tags