Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

How do I trim the zeros off of a mom variable in PB?

I am making a custom command in PB to output the tool info. for each operation, and I want the value to have 4 decimal places but have any zeros trimmed off except for one. Is this possible?

Example of what I am wanting : 4.0

 

I am using the following format but that trims off all zeros and gives me : 4.  

[string trim [format %.4f $mom_tool_extension_length] "0"]

 

It will work but just curious if it is possible to have it 4.0 and still be able to have 4 decimal places when they are not zero.

 

Thanks

4 REPLIES

Re: How do I trim the zeros off of a mom variable in PB?

[string trimright [format %.4f $mom_tool_extension_length] 0]

Solution
Solution
Accepted by MarkRief (VIP)
‎08-26-2015 04:32 AM

Re: How do I trim the zeros off of a mom variable in PB?

[ Edited ]

I just wrote something similar for no decimal for integer

here is an adapted version for your format

 

custom_command in start of program event

 

uplevel #0 {
#============================================================= proc Round2 { in prec} { #============================================================= set tmp [format %.*f $prec $in] if {[expr {fmod($tmp, 1)}]} { return [string trimright $tmp "0"] } else { return [format %.1f $in] } } } ;# uplevel

 use this to call

 

[ Round2 $mom_tool_extension_length 4 ]

 

Re: How do I trim the zeros off of a mom variable in PB?

You may be able to create a format - override MOM_do_template, intercept this format and evaluate, then send on as string format to system MOM_do_template. Look at pb_axis_multipliers.tcl in the pblib directory. This may be more work than you want - but trying to maintain the block templates fuctionality may be worth it.

NX10.03
Windows 7 Pro

Re: How do I trim the zeros off of a mom variable in PB?

Thanks for the replies, I had forgot I had even posted this here.

 

Agrivas' solution looks a lot simpler than what I came up with.

 

Here's how I eventually got what I was looking for.

 

 

Learn online





Solution Information