From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using ini-files with write-key/read-key (double) and defined accurarcy

Solved!
Go to solution

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

0 Kudos
Message 1 of 11
(4,224 Views)
Solution
Accepted by topic author OnlyOne

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):

2014-09-25_10-29-47.png

 

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:

2014-09-25_10-18-39.png

 

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:

2014-09-25_10-21-39.png

 

I couldn't see anything in the numeric/math palettes that does this.


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 2 of 11
(4,219 Views)

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 best solution is the one you find it by yourself
0 Kudos
Message 3 of 11
(4,218 Views)

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.

0 Kudos
Message 4 of 11
(4,209 Views)

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!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 11
(4,191 Views)

@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.

 

 

0 Kudos
Message 6 of 11
(4,187 Views)

>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.

0 Kudos
Message 7 of 11
(4,176 Views)

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!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 11
(4,167 Views)

@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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 11
(4,165 Views)

@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

 

0 Kudos
Message 10 of 11
(4,148 Views)