LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Format into string : Minimum decimal digits

Solved!
Go to solution

Hi! 

 

In a 'format into string' function, I need to define the minimum decimal digits to '2', so that : 

- 0.123456 -> 0.123456

- 123.456 -> 123.456

- 12345.6 -> 12345.60

- 123456 -> 123456.00

 

What format string input can I use for that?

 

0 Kudos
Message 1 of 15
(5,847 Views)

What would define the number of decimals?

 

123.456 isn't an exact number, it's probably 123.456000000000003, or 123.456000000000046. 123.456 can't be represented exactly.

0 Kudos
Message 2 of 15
(5,838 Views)

Sorry, nevermind.

0 Kudos
Message 3 of 15
(5,833 Views)

Ok, I get your point, but that means I am able to set 123.456 in a LabVIEW control, but I am not able to get it as a string. That's mad!

0 Kudos
Message 4 of 15
(5,825 Views)
Solution
Accepted by topic author i.ayestaran

The number control has a formatting (Display Format), you can use Format Into String with the exact format string to get the exact same string as the numeric control.

0 Kudos
Message 5 of 15
(5,816 Views)

Yes, but that's not the case when the number arrives to my code via a shared variable that is written from an external LabVIEW exe.

 

Anyway I accept your answer since I think there is no solution to my 'problem'.

0 Kudos
Message 6 of 15
(5,804 Views)

@i.ayestaran wrote:

Yes, but that's not the case when the number arrives to my code via a shared variable that is written from an external LabVIEW exe.

 

Anyway I accept your answer since I think there is no solution to my 'problem'.


If the shared variable is a string, that's it. The formatting is determined by the sender. If it's a numeric, the formatting is is either a control, or some tool that displays it with a formatting. 

 

I don't thing there's a specifier that let you do exactly what you want.

 

You can always split the number in a "before decimal" and "after decimal" part, or do some string magic with regular expressions.

 

How bad do you want this?

0 Kudos
Message 7 of 15
(5,795 Views)

Don' worry, it's not that important. Would be a nice feature, though.

 

Thanks anyway.

0 Kudos
Message 8 of 15
(5,754 Views)

I'm curious about what you actually expect from this idea.  As Weibe was alluding to, you can have an infinite number of decimal places for most numbers.  So you have to define a maximum regardless.

 

And why do you need a minimum length?  What display mode are you trying to satisfy?  I am genuinely curious about your use case.



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 9 of 15
(5,740 Views)

Brief explanation to satisfy your curiosity 😉 :

 

I have a system where the user can drive an axe to a certain position (ex : 150mm). The HMI does not run in LabVIEW, so the data arrives to my cRIO controller via web request).

The LabVIEW controller calculates in real-time the maximum value the axe can reach depending on several parameters. Thus, even if the user tries to drive the axes to the position 150, the controller may limit its maximum value to the appropriate value, let's say 139.5684.

This 'corrected' value is sent to the HMI as an string.

 

So, if the calculated value is 139.5684, I would like the HMI to be able to display exactly that number, cause that's really the maximum value we can reach.

 

However, in normal conditions we work with three decimal numbers. So if the user requests the value 150 and that value is inside the range, the controller should respond 150.000, thus making the HMI display the value with three decimals, which is the standard in this type of controllers.

 

0 Kudos
Message 10 of 15
(5,730 Views)