Working With European Format Numbers


#1

I’m developing automated testing in Ruby for a product that will be used
in the US and overseas. How can I handle Euro-numbers where commas are
decimal points and the decimal point is a comma?

For example, a US number is 123,456,789.10, but the Euro-version is
123.456.789,10.

Playing around in IRB, Ruby treats the Euro-number like an array.

I’ve googled and checked various forums, but no “ah-HAH!!” moment yet.

Thanks in advance.


#2

Hi, Regis.

Thanks for responding.

number_helper.rb looks useful for going from a string to a properly
formatted currency.

Unfortunately, we are using straight Ruby, not Ruby on Rails. Is there
an equivalent in Ruby?

I also need the ability to convert numbers the customer has entered on
screen or the value of options the customer has selected to floats. US
numbers work fine, but European versions are coming.

Is there a way to tweak the locale settings for numbers, currency, etc.
at run time?

Thanks.


#3

Paul Kmecak wrote in post #1185721:

I’m developing automated testing in Ruby for a product that will be used
in the US and overseas. How can I handle Euro-numbers where commas are
decimal points and the decimal point is a comma?

For example, a US number is 123,456,789.10, but the Euro-version is
123.456.789,10.

Playing around in IRB, Ruby treats the Euro-number like an array.

I’ve googled and checked various forums, but no “ah-HAH!!” moment yet.

Thanks in advance.

See :

https://github.com/svenfuchs/ruby-cldr