Showing results for 
Search instead for 
Do you mean 

TCL fomat REAL to INTEGER but 4 places

[ Edited ]

Good Afternoon guys,


I am new to PB and TCL so without having to write loads of logic is there a quick way to format a numer to AT LEAST 4 whole number places?


So, 41.87654 would become 0041

23768.009 would become 23768


etc etc


Thanks in advance.



Re: TCL fomat REAL to INTEGER but 4 places

Would like to add that I know I can get rid of the trailing values with

format %.0f

This part is good!



I could also take it to 4 integer places with

format %4.0f

but this is no good for integers with only 3 places as it does not apply the preceeding zeros.

It would also shorten 5 place numbers??


Re: TCL fomat REAL to INTEGER but 4 places

[ Edited ]

Ive just done it like this -


 if {$newval < 100} {
    set newval "00$newval"
    if {$newval < 1000 && $newval >99} {
    set newval "0$newval"


Couldnt wait!

Smiley Very Happy 

Re: TCL fomat REAL to INTEGER but 4 places



set newvalue [format %04d [expr int($old_value * 1000)]]


In any case - note that tcl treats numbers that start with "0" as octal numbers, so be careful if you do something more than just MOM_output_text or MOM_output_literal with "newvalue"



Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled

Re: TCL fomat REAL to INTEGER but 4 places

Thanks Ken,


Yeah, they are all output literals.

It is for jumping lines in an Okuma program based on which machine in teh cell is running the program.

GOTO on Okuma looks for your specified marker from the program start. We had problems with programs jumping backwards based on logic.

I am taking the sequence numbers and adding sequence increment calculations to make sure the jump goes forwards.


The code ultimately looks like this -

N0070 G15 H200


N0080 IF[VC199 EQ 154668]N0090

N0085 IF[VC199 EQ 154667]N0100

N0090 G149 E=VC2-90 (TURNCUT MODE ON MC1)

N0095 GOTO N0105

N0100 G149 E=VC2-90 (TURNCUT MODE ON MC2)

N0105 G00 X0.000 Y0.000



Thanks again for your help!

Re: TCL fomat REAL to INTEGER but 4 places

If you specify a new block for the goto using the sequence number word you will not have to do any Tcl magic.


The block would be something like this:

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 ( | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Learn online

Solution Information