Format Rupiah di Ruby
- Last modified atTidak seperti saat menggunakan Ruby on Rails, cara membuat format rupiah dengan Ruby tanpa framework Ruby on Rails boleh dibilang sedikit manual
Format Rupiah di Ruby
# IRB with Ruby 2.5.1
def rupiah(price)
delimiter_regex = /(\d)(?=(\d{3})+(?!\d))/
"Rp. #{price.to_s.gsub(delimiter_regex, '\\1.')}"
end
rupiah 10_000_000
# => "Rp. 10.000.000"
Format Rupiah di Ruby on Rails
Jika menggunakan Ruby on Rails, format mata uang lebih mudah karena Rails menyediakan helper method yang bernama number_to_currency.
# Rails 5.1.6
# in views
example_price = 5_000_000
number_to_currency(example_price, unit: "Rp. ", separator: ",", delimiter: ".")
# => "Rp. 5.000.000,00"
Artikel lain mengenai operasi tanggal di Ruby bisa dilihat di Date Operation in Ruby.
Recent Posts
AWS Secrets Manager
Explanation about AWS Secrets Manager with example code.
Envelope Encryption
Envelope encryption is the practice of encrypting plaintext data with a data key, and then encrypting the data key under another key.
Tutorial - "su username vs su - username" - A Security Perspective
The main difference between `su username` and `su - username` lies in the environment variables that are loaded when switching to the specified user.
Subdomain Hijacking
My dormant subdomain was recently hijacked, redirecting it to a online gamble registration page.
C# DbContext ServiceLifeTime
my note about C Sharp ServiceLifeTime