Forum: Ruby library to rurn money into nominal value?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F50f5d582d76f98686da34917531fe56?d=identicon&s=25 Peter Szinek (Guest)
on 2007-01-24 12:02
(Received via mailing list)
Hi,

I wonder if there is something like $subj so that I don't reinvent the
wheel. What I need is something like:

money_to_val('$12.56')    => 12.56
money_to_val('$ 12.56')   => 12.56
money_to_val('$ 12,56')   => 12.56
money_to_val('US$ 12,56') => 12.56
money_to_val('12.56$')    => 12.56
money_to_val('USD 12.56') => 12.56

maybe even

money_to_val('12 dollars, 56 cents') => 12.56

Probably what I need to cover 95% of the cases is to remove all the
non-digits except a delimiter (, or .) I guess. Or not?

Thanks,
Peter

__
http://www.rubyrailways.com
8029153bbcbda4a6844440c93e0c6422?d=identicon&s=25 Thomas Hafner (Guest)
on 2007-01-24 14:06
(Received via mailing list)
Peter Szinek <peter@rubyrailways.com> wrote/schrieb
<45B73C94.1010405@rubyrailways.com>:

> Probably what I need to cover 95% of the cases is to remove all the
> non-digits except a delimiter (, or .) I guess. Or not?

Attention to locales! At least these variants for 1234567.89 exist in
different countries:
  1 234 567,89
  1.234.567,89
  1,234,567.89
  1 234 567.89
  1'234'567.89
  1,234,567·89
(See <http://de.wikipedia.org/wiki/Dezimaltrennzeichen>.)

Regards
  Thomas
This topic is locked and can not be replied to.