NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Format one digit number into two digit numbers

Solved!
Go to solution

Hi,

 

I encounter a typical problem that consists in formatting all one digit numbers 1 2 3 4 5 6 7 8 9 to 01 02 03 04 05 06 07 08 09.

 

I have read str(  func without finding good format option.

 

What is the easiest way to do this job ?

 

Thank you

0 Kudos
Message 1 of 8
(5,768 Views)

Hi,

 

How do you create the string "1 2 3 4 5 6 7 8 9" ?

where does it come from ?

 

otherwise a .net step on RegEx will provied desired behaviour 

 

Regards

Juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 2 of 8
(5,761 Views)

From Date function, I got 1 or 2 or 3 or 4 or 5 .....number that I convert to string with str( func.

 

How can I format 1 or 2 or 3 to 01 or 02 etc.....

0 Kudos
Message 3 of 8
(5,755 Views)

Hi,

 

I would do it this way:

 

Locals.nSecond = some where from Date()

Locals.strSecond = (Locals.nSecond < 10 ? "0" : "" ) + Str(Locals.nSecond)

 

Hope that helps

 

Juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 4 of 8
(5,750 Views)

Great Thank you !

0 Kudos
Message 5 of 8
(5,747 Views)
Solution
Accepted by niva

Here's an even simpler way:

 

Locals.string = Str(Locals.number, "%.2i")

Message 6 of 8
(5,741 Views)

Hi Doug,

 

it seems it is time for me to read Kernighan & Ritchie once again Smiley Very Happy

Thanks for pointing out!

 

Regards

Juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 7 of 8
(5,734 Views)

To get a better idea of the formats that TestStand supports, you can use the numeric format dialog (on a number variable). The dialog will tell you what the format string is for the options which you select.

 

-Doug

0 Kudos
Message 8 of 8
(5,697 Views)