Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def parse_europ_num(string)
- str = string.dup
- raise "NaN" unless str =~ /^[\d\,\.]*$/
- while str =~ %r{\d{3}\.\d+{3}}; str.sub!(%r{\.}, ''); end
- if str =~ /\./
- raise Exception.new "Improperly formatted string"
- end
- if str =~ /^\d+\,\d+$/
- str.sub!(/\,/, '.')
- end
- if str =~ /\,/
- raise Exception.new "Improperly formatted string"
- end
- return str.to_f
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement