I am storing a cost in my application. The cost is not formatted in the database. For example: 00.00 saves as 0, 1.00 saves as 1, and 40.50 saves as 40.5
I need to read these values from the database and convert them to strings for dollars and cents. For example: 0 –> cost_dollars = ’00’ & cost_cents = ’00’, 1 –> cost_dollars = ’01’ & cost_cents = ’00’, 40.5 –> cost_dollars = ’40’ & cost_cents = ’50’.
Is there an easy way to do this in ruby on rails? Or does someone have code that does this?
Thanks!
You can accomplish that with this little bit of Ruby code: