07-21-2022 12:37 PM
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.
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.
Solved! Go to Solution.
07-21-2022 01:01 PM - edited 07-21-2022 01:08 PM
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:
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.
07-21-2022 01:09 PM - edited 07-21-2022 01:11 PM
Here's what I came up with.

EDIT: Per usual, Altenbach has the better solution.
07-21-2022 01:23 PM - edited 07-21-2022 01:25 PM
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. 😄
07-21-2022 01:28 PM
@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.
☕
07-21-2022 01:30 PM
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.
07-21-2022 01:42 PM
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.
07-21-2022 01:48 PM
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…
07-21-2022 02:03 PM
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.