Advertisement
Guest User

Untitled

a guest
Oct 24th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def parse_europ_num(string)
  2.   str = string.dup
  3.   raise "NaN" unless str =~ /^[\d\,\.]*$/
  4.   while str =~ %r{\d\.\d+{3}}; str.sub!(%r{\.}, ''); end
  5.   if str =~ /\./
  6.           raise Exception.new "Improperly formatted string"
  7.   end
  8.   if str =~ /^\d+\,\d+$/
  9.           str.sub!(/\,/, '.')
  10.   end
  11.   if str =~ /\,/
  12.           raise Exception.new "Improperly formatted string"
  13.   end
  14.   return str.to_f
  15. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement