LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Number format string

Hi to all. I have a question about formatString property when it form a number on indicator or "FormatToString" function.

How can I known the number lenght in simbols by it format string? In some cases it's easy: "%10d" - 10 symbols, but how it works in more complex cases, like "%010_7f" or "%f" or "%g"?

And how calculate symbols after point by formatString?

0 Kudos
Message 1 of 8
(3,340 Views)

Hi Forest,

 

use StringLength after the FormatString function!

(Most often FormatIntoString results in a variable amount of chars…)

Best regards,
GerdW


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

@GerdWuse StringLength after...

I want to know it before the function is done.

0 Kudos
Message 3 of 8
(3,316 Views)

Hi Forest,

 

then you need to analyze your data - it is much easier to check after the conversion to string…

 

Example:

- value of 1 with a format of %g gets converted to "1.000000" (8 chars)

- value of 1 with a format of %#g gets converted to "1" (1 char)

- value of 1 with a format of %#3g gets converted to "  1" (3 chars)

- value of 1.001 with a format of %#3g gets converted to "1.001" (5 chars)

 

It is much easier to check string length after conversion than to analyze all possible input data with all possible format strings…

Best regards,
GerdW


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

@GerdW wrote:

then you need to analyze your data - it is much easier to check after the conversion to string…


Not is it just easier, but a lot of the analysis would require at least most, if not all, of the conversion already.  So you might as well check it after the conversion and make your like A LOT simpler.


GCentral
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 5 of 8
(3,288 Views)

Number of desimal points I calculate like this:
Безымянный.png
And its work in many cases.

0 Kudos
Message 6 of 8
(3,279 Views)

@0Forest0 wrote:

Number of decimal points I calculate like this:
Безымянный.png
And its work in many cases.


So you convert two strings into numbers to figure out the decimal length.  Again, that seems wasteful.  Just convert the original number and use Search/Split String and String Length to get your decimal length.


GCentral
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 7 of 8
(3,264 Views)

When I prepare long string of values I don't know what values (big or not) will convert to string. But I shall put numbers on exactly positions in result string. Then I should know lenght of result string basing on formats of containing values.

0 Kudos
Message 8 of 8
(3,253 Views)