Question about ToNumber - Forum

Forum Navigation
You need to log in to create posts and topics.

Question about ToNumber

@luishp Hi Luis

ToNumber "8 Game " = 8   but ToNumber "Game 8" = nan

Is it normal ?

Regards

@phil78 yes, it's normal. More information abot how it works here.
Regards.

Phil78 has reacted to this post.
Phil78

@phil78

1) A possible workaround would be to build a function that removes all non-numeric characters in the source string; this can be done purely with NeoScript commands, or more efficiently using Javascript and Regex. With both methods, plus and minus signs can be accommodated.

2) It becomes more complicated (but can still be done) when the numbers contain decimal points (dots or commas) requiring the function to separate these from regular fullstop and comma characters e.g.

Apples, Bananas on sale today. As low as $2.37 per Kg.

3) However, this solution will not work if your source string has multiple sets of characters and numbers e.g.

Some numbers like 1234 followed by some text and finally more numbers like 56.78

What do your expected source strings look like ?

 

@gaev  thanks for your reply. I have solve my problem because I was able to split my string and have the numbers before.

I have found also another interesting solution with js match and the pattern /[0-9] +/g which return an array of numbers.

BeginJS
$App.NB = $App.Ligne.match(/[0-9]+/g);
EndJS