mardi 3 novembre 2015

How to do rounding in money gem

i want to modify the moneyrails gem like this. Now in my money gem it is making the price rounding like this (ie;below 15.50 it is exchanging to 15(eg: 15.10 to 15), and if above 15.50 it is exchanging to 16. but i need to modify it like . if it is above 15.01 it should round to 16) (eg: 15.01 or 15.10 or 15.50 or 15.90 it should exchange to 16)

Any way to do like this

i written a condition like this but it is not working , can anyone modify this and help me

Any help is appreciated

in lib i created money.rb model like this

class Money alias :old_exchange_to :exchange_to def exchange_to(other_currency, &rounding_method) value = old_exchange_to(other_currency, &rounding_method) Money.new(value.to_i, other_currency) end end

show.html.slim

humanized_money_with_symbol product.price.exchange_to(@cart.currency)

Aucun commentaire:

Enregistrer un commentaire