SHOW:
|
|
- or go back to the newest paste.
1 | def parse_europ_num(string) | |
2 | str = string.dup | |
3 | raise "NaN" unless str =~ /^[\d\,\.]*$/ | |
4 | - | while str =~ %r{\d{3}\.\d+{3}}; str.sub!(%r{\.}, ''); end |
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 |