Hamilton LaboratoriesHamilton C shell 2012User guideSamples

decimal.csh

Oregon Coast

decimal.csh
Previous | Next

#  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-2012 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 | Next