News for hackers. Stuff that matters.
Re:Show HN: Indian Rupee formatting and word conversion for ... by aboutruby on Tuesday March 19, 2019 @06:42AM (#19429614)
# 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...

# Paisa.words

There is number_to_human which is close: https://api.rubyonrails.org/classes/ActionView/Helpers/Numbe..., otherwise number_to_words's gem https://github.com/kslazarev/numbers_and_words

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

Re:Show HN: Indian Rupee formatting and word conversion for ... by sudhirj on Tuesday March 19, 2019 @09:36AM (#19430644)
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.

Re:Show HN: Indian Rupee formatting and word conversion for ... by aboutruby on Tuesday March 19, 2019 @10:06AM (#19430888)
Oh I see, sorry, didn't look closely enough at the examples. Great project! Maybe this could be upstreamed in Rails?
Re:Show HN: Indian Rupee formatting and word conversion for ... by sudhirj on Tuesday March 19, 2019 @10:57AM (#19431364)
Yeah, that would be ideal. Let me get the algos tightened up with feedback and testing, and I’ll try submitting them.
Re:Show HN: Indian Rupee formatting and word conversion for ... by marvindanig on Tuesday March 19, 2019 @09:49AM (#19430742)
Tremendous, thanks for sharing this gem!
Re:Show HN: Indian Rupee formatting and word conversion for ... by mtmail on Tuesday March 19, 2019 @02:33PM (#19433992)
Re:Show HN: Indian Rupee formatting and word conversion for ... by viraptor on Tuesday March 19, 2019 @06:53AM (#19429666)
https://github.com/RubyMoney/money should cover the formatting for this and many other currencies as well.
Re:Show HN: Indian Rupee formatting and word conversion for ... by sudhirj on Tuesday March 19, 2019 @10:59AM (#19431391)
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.
Re:Show HN: Indian Rupee formatting and word conversion for ... by viraptor on Tuesday March 19, 2019 @06:59PM (#19437018)

    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.
Re:Show HN: Indian Rupee formatting and word conversion for ... by sudhirj on Wednesday March 20, 2019 @01:18AM (#19439229)
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.
Re:Show HN: Indian Rupee formatting and word conversion for ... by aliswe on Tuesday March 19, 2019 @10:32AM (#19431131)
This is amazing.
Re:Show HN: Indian Rupee formatting and word conversion for ... by sudhirj on Tuesday March 19, 2019 @11:04AM (#19431439)
Heh, thanks. I was going for useful, didn’t think currency formatting would invoke amazement.
Re:Show HN: Indian Rupee formatting and word conversion for ... by aliswe on Tuesday March 26, 2019 @03:06AM (#19489791)
No, it is :)
Re:Show HN: Indian Rupee formatting and word conversion for ... by kkarakk on Tuesday March 19, 2019 @07:46AM (#19429909)
2017 tag please
Re:Show HN: Indian Rupee formatting and word conversion for ... by lappet on Tuesday March 19, 2019 @06:23PM (#19436678)
very cool