07-02-2020 04:30 AM
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?
Solved! Go to Solution.
07-02-2020 04:40 AM
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.
07-02-2020 04:43 AM - edited 07-02-2020 04:44 AM
Sorry, nevermind.
07-02-2020 04:54 AM
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!
07-02-2020 05:08 AM - edited 07-02-2020 05:09 AM
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.
07-02-2020 05:18 AM
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'.
07-02-2020 05:34 AM
@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?
07-02-2020 07:34 AM
Don' worry, it's not that important. Would be a nice feature, though.
Thanks anyway.
07-02-2020 08:05 AM
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.
07-02-2020 08:33 AM
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.