strtonum - convert string to number

SYNOPSIS

<strtonum $str [$flag]>


DESCRIPTION
The strtonum function converts each of its string arguments to a numeric (double) value. The strings may be any text quantity that NPM (Metamorph's Numeric Pattern Matcher) can parse.

In version 7.07.1607103000 20201204 and later, an optional flag may be given:

  • bytepowersbinary: Interpret byte-related tokens like kilobyte, kb, megabyte, mb etc. as binary, i.e. powers of 1024. Tokens like kilohertz etc. that are not used in a byte context remain as powers of 1000.

  • bytepowersdecimal: Interpret byte-related tokens as decimal, i.e. powers of 1000. This is the default.


DIAGNOSTICS
strtonum returns the double numeric value of each of its string arguments, or 0 if unparseable.


EXAMPLE

<$txt = "one thousand nine hundred ninety eight"
          "four score and seven years ago"
          "1/3"   "3.14"   "one hundred percent"
          "two thousandths"
          "nine and a half">
  <strtonum $txt>
  <LOOP $ret> $ret </LOOP>

The output would be:

1998 87 0.333333 3.14 1 0.002 9.5


CAVEATS
The strtonum function was added in version 2.1.876800000 19971014.


SEE ALSO
sum


Copyright © Thunderstone Software     Last updated: Oct 24 2023
Copyright © 2024 Thunderstone Software LLC. All rights reserved.