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
KAK Labs Newsletter #6 - Staying Safe From Pegasus Spyware
Newsletter #6 - Pegasus, Ruby, PostgreSQL and networkQuality tool
Material Design - Paragraph Spacing
According to Google's Material Design, keep paragraph spacing in the range between .75x and 1.25x of the type size.
Amazon SDK for C# - S3 File Download Methods
Comparison between `TransferUtility.DownloadAsync`, `DownloadSingleFileAsync`, and `GetObjectAsync`.
Duplicate Content Detection with fdupes Command
Effortlessly locate duplicate files content in Linux using 'fdupes' command.
Broken Pipe Error
My note about Broken Pipe error