How To: Format a real number relation in a note?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
Solved! Go to Solution.
- Labels:
-
2D Drawing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Sorry, just realized I replied to a very old post. The answer you provided was acceptable since the OP was using a note.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
/* 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.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Yeah.. just figured that out just before I read this. Sorry to bother you but thanks for you reply.
Thanks, Matthew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
There was a mistake in the post above. I have corrected it. Sorry about that.
- « Previous
-
- 1
- 2
- Next »