Table of Contents

Text Conversions

These routines perform various conversions or transformations of text strings.


  • func TextToNumber( sequence text )    This converts the text into a number.


    Table of Contents

    [func]
    TextToNumber
    ( sequence text )

    This converts the text into a number.

    Returns: ATOM or SEQUENCE: The number represented by the text. See below for details.

    Category: Text Conversions

    If the text contains invalid characters, zero is returned.

    This function can optionally return information about invalid numbers. If text has the form of {sequence, integer} then if the integer is nonzero, a sequence is returned. The first element is the value converted, and the second is the position in the text where conversion stopped. If no errors were found then this is zero.

    Notes:

  • You can supply Hexadecimal values if the value is preceded by a '#' character, Octal values if the value is preceded by a '@' character, and Binary values if the value is preceded by a '!' character. With hexadecimal values, the case of the digits 'A' - 'F' is not important. Also, any period character embedded in the number is used with the correct base.
  • Any underscore characters, that are embedded in the text number are ignored. These can be used to help visual clarity for long numbers.
  • You can supply a leading or trailing, minus or plus sign.
  • You can supply trailing percentage sign(s). Each one present causes the resulting value to be divided by 100.
  • Any single currency symbol to the left of the first digit is ignored.

         sequence rc
         atom   val
         rc = TextToNumber({"12.34a", 1})
         --  rc ---> {12.34, 6} -- Error at position 6
         rc = TextToNumber({"12.34", 1})
         --  rc ---> {12.34, 0} -- No errors.
    

    val = TextToNumber("12.34a") -- val ---> 0

    val = TextToNumber("#f80c") --> 63500 val = TextToNumber("#f80c.7aa") --> 63500.47900390625 val = TextToNumber("@1703") --> 963 val = TextToNumber("!101101") --> 45 val = TextToNumber("12_583_891") --> 12583891 val = TextToNumber("12_583_891%") --> 125838.91 val = TextToNumber("12583891%%") --> 1258.3891