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

format output with decimal point on non integer values only

We have a machine with a Bosch CC220 control (quite a nice control)

One of its quirks is when calling cycles and sub programs the parameters must have number after the decimal 

 

eg

G81[1.234,0] is OK

G81[1.0,0.0] is OK

G81[1.,0.] error

 

before I write a formatting proc and change all my cycle words to format string,

is there a way with the formatting to output integers with no decimal and non integers without?

 

Enabling trailing Zeros gives three (1.000) which is cluttered.

 

Thanks 

 

Alex

NX903

WIN7pro64

 

2 REPLIES

Re: format output with decimal point on non integer values only

Alex,

What i did for something similar to your issue was checked to see if the number was an integer using a catch command with a formatting switch that only accepts integer values.  It would be nice if Siemens upgraded post builder to use the new TCL/TK 8.6 which has the command "string is" so you can see if your number is an integer or floating point.

 

if { ![catch {format %d $num}] }   {
      set num [format %#.1f $num]
   }

 

Jake Hardwick
CNC Programmer
Senior Aerospace AMT
Production NX8.5.3.3 Beta testing NX10.0.1.4
Solution
Solution
Accepted by MarkRief (VIP)
‎08-26-2015 04:32 AM

Re: format output with decimal point on non integer values only

This is what I ended up using 

 

define word format "Coord_int" 

Numeric 5.0

no Output decimal point

Output traling zeros

(FORMAT Coord_int "&__5_00")

 

call this proc when needed

 

#=============================================================
proc SelectF { name  val } {
#=============================================================
    if {[expr {fmod ([format %0.3f $val],1)}]} {
        MOM_set_address_format $name Coordinate
    } else {
        MOM_set_address_format $name Coord_int
    }
}

 eg

 

global mom_cycle_step1

SelectF cycle_step $mom_cycle_step1

 

 

Learn online





Solution Information