09-25-2014 04:06 AM
Hello,
in a popup the user can insert a numeric-double-value.
This value is saved in a ini-file using the Write-key-vi with Type = double. Works fine.
What do i have to do to set the values after the comma?
So if user inserts 1,532 i want to round to two digits after comma and save it. (-> 1,53)
Thx
Solved! Go to Solution.
09-25-2014 04:27 AM - edited 09-25-2014 04:31 AM
I don't know how LV deals with different decimal seperators (e.g. comma instead of point), I guess it 'just works' depending on the system locale.
A few different options are available as follows...
The Write Key function has a 'precision' input which will set the number of decimal places to save the DBL to (in your case, set this to 2):
If you are using a numeric field, you can set the 'increment' property with 'coerce to nearest' to prevent them from entering more precision than is available:
The obvious method for post-rounding the input is to scale up the number, round to the nearest integer and then divide again to limit the precision:
I couldn't see anything in the numeric/math palettes that does this.
09-25-2014 04:30 AM
What type of value is 1,532 and rounding to 1,53, Am sorry I don't understand why are you trying to do this.
09-25-2014 04:39 AM
P@Anand wrote:
What type of value is 1,532 and rounding to 1,53, Am sorry I don't understand why are you trying to do this.
I think he is using string as a control but the question is why strings when you can do it with just simple DBL.
Anyways 1,532 does not make any sense with Numeric contol.
09-25-2014 05:00 AM - edited 09-25-2014 05:01 AM
Hi,
Anyways 1,532 does not make any sense with Numeric contol.
"1,532" does make a lot of sense when used in a non-English locale context…
@OnlyOne:
Convert your numbers to string before writing them to your ini file and convert them bacl when reading in…
And good advice: change your locale settings to use English conventions!
09-25-2014 05:09 AM - edited 09-25-2014 05:10 AM
@GerdW wrote:
Hi,
Anyways 1,532 does not make any sense with Numeric contol.
"1,532" does make a lot of sense when used in a non-English locale context…
Sorry Gred , Did not get you properly.
09-25-2014 05:23 AM
>What type of value is 1,532 and rounding to 1,53, Am sorry I don't understand why are you trying to do this.
The value is inserted in a double-control on the popup.
So user can insert whatever he wants.
But i only want to save values in the ini-file that are valid.
The values are later read and used for instrument-configuration - and instrument precision is mV.
09-25-2014 05:38 AM - edited 09-25-2014 05:39 AM
Hi Neos,
there are a lot of countries using the comma as decimal separator. So 1,532 is a valid float number for a non-English locale (Windows regional settings)…
@OnlyOne:
Why don't you limit the numeric input to valid values? You can set a range and an increment to limit input values!
09-25-2014 05:41 AM
@OnlyOne wrote:
>What type of value is 1,532 and rounding to 1,53, Am sorry I don't understand why are you trying to do this.
The value is inserted in a double-control on the popup.
So user can insert whatever he wants.
But i only want to save values in the ini-file that are valid.
The values are later read and used for instrument-configuration - and instrument precision is mV.
As mentioned, the easiest way is to set the display format of the control to 2 precision (to show the user), and a constant 2 to the precision input of the Write key (so it is infact written with 2 decimals).
(if using decimal comma, where are you from, btw?)
/Y
09-25-2014 06:22 AM
@GerdW wrote:
Hi Neos,
there are a lot of countries using the comma as decimal separator. So 1,532 is a valid float number for a non-English locale (Windows regional settings)…
Ok, Thank you Gred