
Show HN: Indian Rupee formatting and word conversion for Ruby - sudhirj
https://github.com/sudhirj/paisa.rb
======
aboutruby
# Paisa.format / Paisa.format_with_sym

This can be done with Rails's number_to_currency helper:
[https://apidock.com/rails/ActionView/Helpers/NumberHelper/nu...](https://apidock.com/rails/ActionView/Helpers/NumberHelper/number_to_currency)

# Paisa.words

There is number_to_human which is close:
[https://api.rubyonrails.org/classes/ActionView/Helpers/Numbe...](https://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-
i-number_to_human), otherwise number_to_words's gem
[https://github.com/kslazarev/numbers_and_words](https://github.com/kslazarev/numbers_and_words)

I would actually recommend using the money gem to handle money objects:
[https://github.com/RubyMoney/money](https://github.com/RubyMoney/money)

~~~
sudhirj
All of the methods and libraries assume regular grouping, but India's money is
grouped irregularly. While regular money is counted in groups of 10^3
(thousands, millions, billions, trillions), in India there's a 3,2,2 cycle.
One lakhs = 100,000 and 1 crore is 100 lakhs, but if you had 1000 of them it
would still be a thousand.

Everybody seems to get this wrong, even Google Sheets.

~~~
aboutruby
Oh I see, sorry, didn't look closely enough at the examples. Great project!
Maybe this could be upstreamed in Rails?

~~~
sudhirj
Yeah, that would be ideal. Let me get the algos tightened up with feedback and
testing, and I’ll try submitting them.

------
mtmail
Ages ago we wrote something similar for Perl
[https://metacpan.org/pod/Number::Format::SouthAsian](https://metacpan.org/pod/Number::Format::SouthAsian)
supporting the
[https://en.wikipedia.org/wiki/Indian_numbering_system](https://en.wikipedia.org/wiki/Indian_numbering_system)

------
viraptor
[https://github.com/RubyMoney/money](https://github.com/RubyMoney/money)
should cover the formatting for this and many other currencies as well.

~~~
sudhirj
I’m not seeing support for irregular cycles - in all these libs you can
customise the 10^3 separator and the decimal mark, but the problem in India is
that the separators follow a 10^3,10^2,10^2 repeating separator cycle.

~~~
viraptor

        Money.new(10000000, "INR").format(south_asian_number_formatting: true)
        #=> "1,00,000.00"
    

If there are any other cases missing, I'm sure they'd be interested to know.

~~~
sudhirj
Ah, thanks. Never thought of searching for "south asian". Let me see if that
covers all the cases, will either deprecate or use the Money gem internally.

------
aliswe
This is amazing.

~~~
sudhirj
Heh, thanks. I was going for useful, didn’t think currency formatting would
invoke amazement.

~~~
aliswe
No, it is :)

------
kkarakk
2017 tag please

------
lappet
very cool

