LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do i conver number to string such that the spaces to the left of the numbers become zeros?

Hi all,

I am saving .txt files by the order they occur, ie. 1.txt, 2.txt,.... etc. but i need 3 zeros to the left so they get saved as 0001.txt , ...., the number itself comes from a recursive file list and i can't seem to convert it properly... I tried number to decimal string using a width of 4 and then I used "format into string" with "%[0] " in the "format string" section which doesn't convert the spaces to zero as it says it should in th format specifier syntax, am i using the wrong VI or is the argument not typed out correctly? ....

Thanks

G

0 Kudos
Message 1 of 11
(4,595 Views)

gx,

 

You're on the right track.  Try this.

 

Leading Zeros_BD.png

Message 2 of 11
(4,585 Views)
The %[0] is not at all correct. You could simply right click on the format into string and select 'Edit Format String' or use %04d.txt as the format string.
0 Kudos
Message 3 of 11
(4,583 Views)

Worked Perfectly thanks a lot...

Greg

0 Kudos
Message 4 of 11
(4,565 Views)

Instead of starting a new thread, I thought I would add on to this one. This solution works for decimal numbers, but how do I get it to work for float numbers?

 

I want to convert "5.3" from a numeric control into string "005.30".

0 Kudos
Message 5 of 11
(4,357 Views)

hope it helps

Please remember to accept any solutions and give kudos, Thanks


LV 8.6.1, LV2010,LV2011SP1, FPGA, Win7
0 Kudos
Message 6 of 11
(4,351 Views)

Same difference. Use %06.2f as format, for example.

 

0 Kudos
Message 7 of 11
(4,350 Views)

@Akiel wrote:

hope it helps


your answer has nothing to do with floating point numbers and makes no sense.

0 Kudos
Message 8 of 11
(4,347 Views)

it does if you take into account when i started the message this thread was blank, unfortunatly it moved on alot before I posted and hence as you say is irrelevant to what your talking about now.

Please remember to accept any solutions and give kudos, Thanks


LV 8.6.1, LV2010,LV2011SP1, FPGA, Win7
0 Kudos
Message 9 of 11
(4,344 Views)

@Akiel wrote:

it does if you take into account when i started the message this thread was blank,...


This thread started in 2009, so I doubt that. 😄

 

In any case formatting with leading zeroes is a common operation and has full support in the format codes. No need for string operations. 😉

Message 10 of 11
(4,338 Views)