Table of Contents
Previous Sample | List of Samples | Next Sample

Decimal.csh


#  Evaluate a string as a decimal number.
#
#  Overcome the shell's usual interpretation of a string with leading
#  zeroes as an octal number, forcing, e.g., 0170 to evaluate as 170,
#  not 120.

#  Copyright (c) 2001 by Hamilton Laboratories.  All rights reserved.

proc decimal(x)
   local i, j
   for i = 1 to strlen(x) do
      @ j = substr (x, i)
      if (j =~ '[1-9]*' && isnumber(j)) return j + 0
   end
   return 0
end

decimal $argv



Previous Sample | List of Samples | Next Sample
Table of Contents



Copyright © 1988-2003 by Hamilton Laboratories. All rights reserved.