Price Formatting in Python

Member

jerald_rippin

by jerald_rippin , in category: Python , 25 days ago

Price Formatting in Python

1
2
3
4
5
6
7
def format_price price, delimeter = ' '
  s, i = price.to_s.reverse, 0
  Array.new(s.size) do |n|
    c = n.zero? ? '' : ((i += 1) % 3).zero? ? delimeter.to_s : ''
    c + s[n, 1]
  end.join.reverse
end


Facebook Twitter LinkedIn Telegram Whatsapp Pocket

no answers