-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rails: add support for :decimal field instead of cents/integers #25
Comments
You should be able to use |
I agree with gamov. No longer than yesterday I had to implement a new routine in one Rails app to deal with money. Indeed, users can't play with cents. I can't ask to an user "Enter here your order price in cents". While I was working on the feature, I realized that Money could probably be improved on this side. I'd like to propose a few additional methods: Money.parse([String]) Equivalent to String.to_s.to_money or viceversa. Ideally, I would be able to call
Money.new_from_decimal([Fixnum/Float], ...) (or ala Objective-C new_with_decimal) Equivalent to Money#decimal Gets/Sets the value in Fixnum/Float. I'm sure these methods will significantly improve the library. |
What about just enhancing
|
Honestly, I would consider to keep them separate. For instance, it would be hard to understand if Money.new(10) should be 10 cents or 10 dollars. I believe using separate method provides additional security and readability, in this case. |
Okay, I can agree with that. How about something like this then?
They're unambiguous, and we can easily add more methods in the future. In this case I wouldn't use |
I agree. Would this implementation also include |
I'd avoid |
do you want to write these methods weppos? |
Sure, I can work on them. I'll try to get the patch within tomorrow. |
I agree with weppos that it must be clear when Money will deal with :decimal instead of cents. Why not #from_dec? It seems you consider the evil float equal to the righteous Bigdecimal. |
We always try to avoid coupling the Money library with Rails. Once these methods will be in place, you'll be able to accomplish the task defining your own composed_of configuration. |
We could add a |
I can implement these if you don't have time, weppos. |
I'm quite busy right now, but I'd like to work on it to break from my current daily activity. |
sounds good :) |
hey guys, one more newbie question: I wanted to had the blue 'enhancement' label to this issue, I couldn't figure how. Do you need some kind of admin rights? |
You have to be a contributor to add labels, close issues, etc. |
Cool. thanks for your help! |
Now that I have a few minutes to stop and relax, I'm reviewing all the comments to this issue to organize the changes. I'd like to summarize all the activities for a final feedback. Honestly, there's also a small piece of these changes that doesn't please me very much. I'm going to explain why. First, the goal of this ticket: add support for getting/setting/creating Money objects from a
The idea is to have something like
Here's my first question. I'm not a native English/American speaker so forgive me if this is a stupid question. We initially agreed on using
This word will be consistently use across the entire library, so that we can implement
Needless to say, the Second question is: do we really need a list of
In my opinion, we should abstract the money implementation from a specific data type and the ticket #27 is an excellent demonstration. I believe Money should provide methods to create money from "concepts", rather than from "types". What does it means in practice? First, we can provide a reasonable set of allowed types when defining a method API. For instance, Then, we can add more "meaningful" methods to extend Money usage always trying to work with concepts rather than types (Ruby is not really a strongly typed language). There's an small exception to my feedback. We can think about adding more
String deserves a special mention here because a
This is the reason why we can try to provide two methods:
The idea behind this change is to clean up the core_extensions by moving all the logic into the To summarize:
and update the core extensions accordingly. We can also decide to move the section 2 to an other ticket. Sorry for the very long comment. |
I like the ideas, but the word I'd also like to see a separate ticket (and set of patches) submitted for the core extensions cleanup. |
I don't like very much the word See http://github.com/RubyMoney/money/compare/master...issue_25 Any feedback before the merge? There are a couple of |
Looks good, one minor thing, in the specs, can you use |
Sure! |
Add support for creating objects with the main monetary unit instead of cents (closed by 1172245) |
|
It please me more than #dollars. Let's see semmons99's feedback. |
Units is ambiguous, it can refer to either dollars and cents. I understands that dollars is specific to a handful of countries (approximately 36 countries use the dollar to refer to their whole unit of money), but so is cents (approximately 42 countries). I'd rather use a term that a majority of people understand and can reason about, than something more ambiguous that everyone would be forced to look at documentation for. |
Ok, let's leave |
If dollars/cents is an issue, we could always add two new keys to the Currency table for |
Yes, I think it's nicer to have those two additional methods (whole_units/fract_units) semmons99. |
If we go this direction, I would actually add |
At this point, I suggest to go ahead with the current implementation (cents and dollars) and keep things as simple as possible. We can always try to implement different solutions in the future, based to real-world usages and feedback. |
sounds good |
Trivial to implement but would be nice to have it built-in
The text was updated successfully, but these errors were encountered: