I18N-tools


about
The I18N-tools provide conversion from numerics to strings and back. For this it takes the locale into account.

example usage
The LANG environment variable on the system, is set for this examples to de_DE.utf8

require 'i18n-tools'

# Without an argument to initialize the locale is set to the systems locale
numeric = I18nTools::LcNumeric.new

p numeric.to_s -234_567, :separator => true
# >> "-234.567"
p numeric.to_s -234_567.89
# >> "-234567,89"

p numeric.to_i '12.345,67'
# >> 12345
p numeric.to_f '-123.456,78'
# >> -123456.78


# Now we initialize with an other locale
numeric = I18nTools::LcNumeric.new 'en_GB.UTF-8'

p numeric.to_s -234_567, :separator => false
# >> "-234567"
p numeric.to_s -234_567.89, :separator => true
# >> "-234,567.89"

p numeric.to_i '12,345.67'
# >> 12345
p numeric.to_f '-123,456.78'
# >> -123456.78

how to install
change with the terminal into the source directory and then do the following steps:

~$ruby setup.rb config
~$ruby setup.rb setup

get root / superuser

#ruby setup.rb install

bugs
From the grouping from the locale only the first element is used. For most languages it is sufficient.
to_f and to_i doesn't test the string for validity.

contribution

If you want to contribute just fork this project and send me a pull request with your changes. If you have any questions just drop me a line to detlef!reichl()gmx!org.