Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

Handle money in Rails

Rails • Asked by Wouter van den Beld

Hi,

What do you think is the best way to handle money in rails?
At the moment i use a decimal field with a precision if 16 and a scale of 2.

the problem is that we use the comma as a decimal sign and this sometimes becomes a problem.

should i use the money gem or use only cents or do you guys have a better way to handle this?


Oh that's a really interesting question. I've never really considered that because we only use it in the other notation.

I would imagine that the Money gem can do the conversion for you and that internally it really saves them as decimals but tweaks the string output so that it uses comma for the decimal. I think you would want to continue saving with the decimal format and then have a method that converts the value into a Money object and that would be what you interact with. You could also probably have a setter method that lets you set the value via the comma version of the string which converts to the decimal one in the database.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.