LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to scan numbers with both decimal separators from string

Hello everyone,

 

How to scan for a number regardless of whether decimal separator is a comma (,) or a dot (.)?

 

I am aware that you can specify one or the other (%. or %,), but how can I make that both "6,4" and "6.4" would be converted to a number?

 

Now I am using "Scan From String".

 

The only option I see is to replace all the dots by commas. Can it be natively done with "Scan From String"?

 

0 Kudos
Message 1 of 5
(1,381 Views)

@nicknamenickname wrote:

The only option I see is to replace all the dots by commas.


That's what I would do (except replace all commas with periods 😉 )

 

(I am sure you know that you can do it in one step when selecting "replace all=TRUE")

Message 2 of 5
(1,372 Views)

Hello nickname,

 

Can it be natively done with "Scan From String"?

Nope, not to my knowledge.


@nicknamenickname wrote:

Hello everyone,

 

How to scan for a number regardless of whether decimal separator is a comma (,) or a dot (.)?

 

I am aware that you can specify one or the other (%. or %,), but how can I make that both "6,4" and "6.4" would be converted to a number?

 

Now I am using "Scan From String".

 

The only option I see is to replace all the dots by commas.

 


I think that's one valid option. I sometimes implented a check it my number string contains a dot and then selected the appropiate format-string %.,%f or %,;%f



Regards, Jens

Kudos are welcome...
0 Kudos
Message 3 of 5
(1,351 Views)

For others who might land on this page in the future there is a type here. FYI, the format string specifier is: 

 

%.;%f - for decimal

%,;%f - for commas

Message 4 of 5
(154 Views)

@bharadwajRamesh wrote:

For others who might land on this page in the future there is a type here. FYI, the format string specifier is: 

 

%.;%f - for decimal

%,;%f - for commas


That's not really a solution to the actual problem.

 

What NI does in their ini file functions is maybe not very performant but quite slick and solving the actual problem. They try to convert with both formats with two separate Scan from String nodes, comparing the result of the output index from both with each other and choosing the result that scanned more characters as valid number.

rolfk_0-1741095330324.png

 

 

  

Rolf Kalbermatter
My Blog
Message 5 of 5
(127 Views)