Forum: Ruby Working With European Format Numbers

32a13da83bcee2d32ed0e74d0be9c2b1?d=identicon&s=25 Paul Kmecak (paulkmecak)
on 2017-03-27 16:55
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.
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2017-03-27 19:36
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 :

http://api.rubyonrails.org/classes/ActionView/Help...

https://github.com/svenfuchs/ruby-cldr
32a13da83bcee2d32ed0e74d0be9c2b1?d=identicon&s=25 Paul Kmecak (paulkmecak)
on 2017-03-27 20:16
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.