6 comments

  • aboutruby 1865 days ago
    # 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

    • sudhirj 1865 days ago
      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 1865 days ago
        Oh I see, sorry, didn't look closely enough at the examples. Great project! Maybe this could be upstreamed in Rails?
        • sudhirj 1865 days ago
          Yeah, that would be ideal. Let me get the algos tightened up with feedback and testing, and I’ll try submitting them.
      • marvindanig 1865 days ago
        Tremendous, thanks for sharing this gem!
  • mtmail 1865 days ago
  • viraptor 1865 days ago
    https://github.com/RubyMoney/money should cover the formatting for this and many other currencies as well.
    • sudhirj 1865 days ago
      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 1865 days ago

            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 1865 days ago
          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 1865 days ago
    This is amazing.
    • sudhirj 1865 days ago
      Heh, thanks. I was going for useful, didn’t think currency formatting would invoke amazement.
      • aliswe 1858 days ago
        No, it is :)
  • kkarakk 1865 days ago
    2017 tag please
  • lappet 1865 days ago
    very cool