LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Format into string specific format

Solved!
Go to solution

I have a device that wants an ascii command in the format of "PRxx.xxx" where x is the set point value. I can get 3 digits of precision or 2 significant digits (with no decimal) but not both using the format into string value. To me it seems like the documentation for using the "0" format specifier is wrong. It works for formatting into integers, but not floating point numbers.

 

0-format-specifier.png

format-into-string.png

 

I can get the desired output by concatenating some strings, but I thought this would be something that can be handled by format into string pretty easily.

 

0 Kudos
Message 1 of 9
(6,257 Views)
Solution
Accepted by StevenD

The first number is the entire field width, not just for the integer part:

 


@StevenD wrote:

I have a device that wants an ascii command in the format of "PRxx.xxx" where x is the set point value.

 


So this would do:

 

altenbach_0-1658426880880.png

 

 

You might want to do some range checking on the value to ensure that the value is 99.999 or less, not negative, and not e.g. NaN, etc.

 

0 Kudos
Message 2 of 9
(6,246 Views)

Here's what I came up with.

 

EDIT: Per usual, Altenbach has the better solution.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 9
(6,235 Views)

I understand the confusion because just looking at the format makes us guess that the first number is for the integer part.

 

To be fair, the LabVIEW documentation is quite clear here, but who reads it. 😄

 

 

altenbach_0-1658427689203.png

 

 

 

Message 4 of 9
(6,228 Views)

@crossrulz wrote:

 

EDIT: Per usual, Altenbach has the better solution.


 

It's Friday, and a long weekend Friday here. I thought I was missing something simple. Glad to see I wasn't alone. I will consult the bean juice more thoroughly next time. 

0 Kudos
Message 5 of 9
(6,221 Views)

 

You might want to do some range checking on the value to ensure that the value is 99.999 or less, not negative, and not e.g. NaN, etc.

 


Range checking is done with some good old fashion data entry limits on the control.

0 Kudos
Message 6 of 9
(6,219 Views)

Actually, here it is still Thursday morning, but it could be Friday somewhere. 😄

 

If you allow negative numbers, you need to constrain as follows,  i.e. -9.999 to 99.999 to keep it within 6 fields.

0 Kudos
Message 7 of 9
(6,209 Views)

Hi Steven,

 


@StevenD wrote:
Range checking is done with some good old fashion data entry limits on the control.

This will fail once you call this routine as a subVI: data entry limits only work for user inputs…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 9
(6,199 Views)

I am aware, the VI shown was just a simplified example. In my actual project it's a pretty UI control with limits coresced to device specific range.

0 Kudos
Message 9 of 9
(6,194 Views)