NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Active Participant
CoastalMaineBird
Posts: 1,801
0 Kudos

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


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Proven Zealot
GerdW
Posts: 7,156
0 Kudos

Re: How to make string using N significant figures?

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


CLAD, using 2009SP1 + LV2011SP1 on WinXP+Win7+cRIO
Kudos are welcome :smileywink:
Member
Phil Brooks
Posts: 7

Re: How to make string using N significant figures?

[ Edited ]
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
Active Participant
CoastalMaineBird
Posts: 1,801
0 Kudos

Re: How to make string using N significant figures?

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


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Active Participant
CoastalMaineBird
Posts: 1,801
0 Kudos

Re: How to make string using N significant figures?

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


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Trusted Enthusiast
DFGray
Posts: 2,569
0 Kudos

Re: How to make string using N significant figures?

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)
Using LabVIEW 2009 - 2012 on Windows 7 64-bit
By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page