Re: convert numbers
- Posted by irvm at ellijay.com Oct 12, 2003
- 491 views
On Sunday 12 October 2003 04:37 am, Louis wrote: > The value() function does not simply return a number. It returns two > things: a success/failure message and the number. Not as easy to use in a > calculation as above. Although value() is more rigorous than s2n(), I > suspect s2n() is much faster. Indeed, your function is 5 to 8 x faster than value(). Which makes me think that I should take a look at some of my programs which use value() heavily - maybe I could speed them up significantly by writing my own conversion routines. Irv > ----------------------------------------------------------------- > -- s2n -- Convert a numeric text string to an integer > -- Note: This only works for positive integers > ----------------------------------------------------------------- > global function s2n(sequence s) > atom n > s -= '0' -- Convert ASCII to BCD > n = s[1] -- First digit > for i = 2 to length(s) do > n = n*10 + s[i] -- The rest of the digits > end for > return n -- Return the number > end function