08-02-2021 02:13 PM - edited 08-02-2021 02:19 PM
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"?
08-02-2021 02:29 PM - edited 08-02-2021 02:30 PM
@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")
08-02-2021 03:10 PM
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
03-03-2025 01:33 PM
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
03-04-2025 07:36 AM
@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.