LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make string using N significant figures?

LabVIEW 8.2:

If I have a numeric indicator, I can set it up (FORMAT & PRECISION) like this :

Precision type: Significant Digits #Digits: 5 Hide Trailing Zeroes: TRUE

This turns the value 1.234567 into "1.2345" the value 12.34567 into "12.346", the value 123.4567 into "123.46", and the value 12.3 into "12.3". The number of decimal places shown varies according to the number's magnitude.

How can I convert a number to a string using that same behavior? FORMAT INTO STRING gives me no options for significant figures, only decimal places.

None of the other number -- string functions do it either, that I see.

Am I missing something? Or do I have to roll my own?

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 1 of 8
(5,255 Views)
Hi CoastalM...,

have you tried to use a format code of "%5f"???

When you don't succeed here, you can always check for ranges and use a different format code for each range of numbers...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(5,246 Views)
You can use the same format string from the numeric properties dialog to format a number to a string.

To see the actual string used to format the number, select the advanced radio button. Copy the string and use this in your format to string call.




Message Edited by pbrooks100 on 05-23-2008 07:38 AM
Message 3 of 8
(5,242 Views)
EXACTLY!

That option is not listed in the help for FORMAT INTO STRING, and I didn't think of extracting it from the dialog using ADVANCED EDITING.

Thanks.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 8
(5,226 Views)
have you tried to use a format code of "%5f"???

Well, that just turns 1.234 into "1.234000". It defaults into 6 dec. places - no help.

When you don't succeed here, you can always check for ranges and use a different format code for each range of numbers...

Yeah, that's the "roll-my-own" I was hoping to avoid.

But the "%#_5g" code works!

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 8
(5,222 Views)
The option is listed in the Format Specifiers Syntax Elements topic in the LabVIEW 8.2.1 help.  The # element removes trailing zeroes.  The _ instead of a . specifies significant digits instead of precision.

I know this is confusing because it usually takes me several tries to get things the way I want them.  The Format Specifier Syntax topic also include these options, but in more concise form.  The elements have been there are far back as LabVIEW 7.0 (the earliest LabVIEW I have on my machine)
0 Kudos
Message 6 of 8
(5,161 Views)

Old thread but still a intresting subject.

I want to get rid of the # in the format specifier. When I have 999.333 as stimuli and wants 2 sign. digits I get 1E10^3. It should be 1.0E^3.

Without the # I get the latter one. 

 

snipp_sign_digits.png

0 Kudos
Message 7 of 8
(381 Views)

Hi Shakti,

 


@Shakti211 wrote:

snipp_sign_digits.png


You forgot to attach your subVI. (It's not magically included in the snippet!)

What's the point of the empty string constant?

Best regards,
GerdW


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