LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I....

.....write a function that transform a number between 0 and 999 in a string
of three digit. That is : 1 --> '001' ; 20 --> '020'; 26 --> '026'; 678 -->
'678'. I use Labview 5.1..

Thanks
0 Kudos
Message 1 of 6
(3,536 Views)
May be I'm wrong, but already in 5.1 you must have 'format to string' function, where you can set the minimum length of a number of digitss in its string representation to 3 (or any other) and to fill extra space with zeros (use as format string "%03d" - this will result in a 3-digit number with leading zeros)
Message 2 of 6
(3,536 Views)
Since I don't remember which functions where available in LV5, I propose 2 solutions
1/ ...works with all LV versions :
Wire your numeric to a "Number to Decimal String" function, and set the width to 1 (don't worry about numbers with more than 1 digit, there is no truncation). Get the resulting string length, and wire it to a case structure, to handle the different possibilities.
Set the "0", default case, to "3", and wire your string through the case structure, to an indicator.
In the "1" case, concatenate a "00" string to the (single digit) string.
Create a "2" case, and concatenate a "0" string.

2/... works in LV 6 and 7
Use a "Format into string" function, with the format string set to "%03d"

I wanted to send you a .jpg for illustration, but
I can't add any file to this answer (problem with NI server ?). Sorry...
Hope this help !
Chilly Charly    (aka CC)
0 Kudos
Message 3 of 6
(3,536 Views)
Thank you. Your solution for LV5 works correctly.
So the solution of djadjok.. There are a lot of functions in LV that I don't
know!! 😞

Now I have an other question..
This time i have to trasform a decimal number (two decimal digit) in a
string...
0,12 -->'0.12'
2,32 -->'2.32'
........
I don't know if there is a similar function....



chilly charly wrote:
> Since I don't remember which functions where available in LV5, I
> propose 2 solutions
> 1/ ...works with all LV versions :
> Wire your numeric to a "Number to Decimal String" function, and set
> the width to 1 (don't worry about numbers with more than 1 digit,
> there is no truncation). Get the resulting string length, and wire it
> to a case structure, to handle the different possibilities.
> Set the
"0", default case, to "3", and wire your string through the
> case structure, to an indicator.
> In the "1" case, concatenate a "00" string to the (single digit)
> string.
> Create a "2" case, and concatenate a "0" string.
>
> 2/... works in LV 6 and 7
> Use a "Format into string" function, with the format string set to
> "%03d"
>
> I wanted to send you a .jpg for illustration, but I can't add any file
> to this answer (problem with NI server ?). Sorry...
> Hope this help !
0 Kudos
Message 4 of 6
(3,536 Views)
You can as earlier use "format to string" function using "%.2f" (.2 - to set precision to 2 decimal digits, f - floating point number)as format specifier or use standalone "Number to fractional string" function also setting precision to 2 (default value is 6).
0 Kudos
Message 5 of 6
(3,536 Views)
Apparently, you also have to deal with the separator (comma versus dot). Use the "Search and Replace String" function (again in the String sub-palette), after the "Number to Fractionnal String" as indicated by Djadjok.
Chilly Charly    (aka CC)
0 Kudos
Message 6 of 6
(3,536 Views)