LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String to Number conversion

Solved!
Go to solution

Hi,

 

I am passing it first to Teststand and there to microcontroller via serial bus (RS232).

 

Jick

0 Kudos
Message 11 of 46
(2,720 Views)

To make things clear:

You have a string like -73.28

--> If you want to calculate something, it´s useful to convert this string into a number, in that case into a floating point - also short called double (DBL) for having maximum resolution, so that the CPU can do number handling.

 A DBL (double) is nothing else than a 8 byte data value with a defined structure that can be handled inside the OS/CPU.

 

For us simple "stupid" humans, to make is more readable, the representation of this 8 bytes is done in a human readable format--> this depends on what system settings you have/country where you are.

i.e. Germany -> it´s the , --> US --> it´s the .

This does not mean, that the number that is hold in the memory has really a commata or a point in it! 

 

This is the reason, why you have to give your "format" function the information if the source data contains a point or commata.

If systems setting is ",", formatting -73.28 results in -73,0 (i.e. on german systems.)

The same happens, if you have the string "-73,28" and convert it on an english system, the result is -73.0

 

So for your special problem:

If you have a string -73.28 and you have to give it to Teststand and then to a uC - if you do not have to make any calculations in between, why do you not transfer the string from LV to TS and to the uC?

 

Stefan

 

0 Kudos
Message 12 of 46
(2,706 Views)

Yes, I undestand country specific styles between "," and ".".

My procedure is:

1. Parse number out from a string i.e "... -73.12..." in LV.

2. Convert it to -73.12 number. Pass it to TS.

3. Make some basic calculations like plus and minus with other results in TS.

4. Convert it to string and send to uC.

 

So if the number includes comma "," in step 3. and/or step 4. I'll get an error.

 

Jick

 

0 Kudos
Message 13 of 46
(2,696 Views)

Very simple solution to the location problem:

 

Why don't you just do a search and replace function that you can run on all your Strings (numerics) that you output from your program that replaces all commas with decimal points?

 

input 1: 71.28

output 1: 71.28

input 2: 71,28

output 2: 71.28 

input 3: 73

output 3: 73

 

2 controls: "String", "Is numeric"

1 Indicator: "Processed string"

 

 

James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 14 of 46
(2,687 Views)

I ended up to change my OS's regional settings. Thanks to everyone!

 

Jick

0 Kudos
Message 15 of 46
(2,673 Views)

Word of warning: 

 

Changing the regional settings works.... until you port the code onto another machine and forget why you have the failure. I suspect many people would agree with me when I suggest you fix the problem properly in the LabVIEW code so you don't see it again rather than risk a headache in 6 months time when you've forgotten why this is happening and your PC has just been replaced!

 

You will probably pay later for your "laziness" now.

 

James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
Message 16 of 46
(2,671 Views)
Good point. I added a note into the LV code. Thanks!
0 Kudos
Message 17 of 46
(2,660 Views)

Jick wrote:

Yes, I undestand country specific styles between "," and ".".

My procedure is:

1. Parse number out from a string i.e "... -73.12..." in LV.

2. Convert it to -73.12 number. Pass it to TS.

3. Make some basic calculations like plus and minus with other results in TS.

4. Convert it to string and send to uC.

 

So if the number includes comma "," in step 3. and/or step 4. I'll get an error.

 

Jick

 


So the problem is more Teststand related?

Or do you do step 4 in LabVIEW?

 

For conversion, you should use the 'Format into string' function with a '%.;' at the start of the formatter, this instruct LabVIEW to use a '.' as decimal sign.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 18 of 46
(2,637 Views)

The problem is/was my microcontroller which does not understand "," as a decimal separator. In LV when converting string i.e. "-22.22" to number I get -22,22 instead of -22.22. I already changed OS's settings about decimal separator.

 

 

Jick

0 Kudos
Message 19 of 46
(2,634 Views)

Hi Jick,

 

the problem is not the µC nor the OS!

The problem is an "incomplete" formatting in LV or TestStand...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 20 of 46
(2,622 Views)