This project is archived and is in readonly mode.
number_to_currency doesn't format negative numbers correctly
-
Don Wilson
Whoops, I should have put [PATCH] in the subject and I didn't.
-
Prem Sichanugrist (sikachu)
- Importance changed from to Low
+1 for this patch. Test case looks good.
However, I somehow think it would be nicer if I supply
%n %uas the format and it would automatically set-%n %uas the negative format. Do you think that would be possible?Thank you.
P.S. the
[PATCH]convention is not required anymore, so no problem :) -
Don Wilson
Good idea. I have made that change. The negative format is now "-" + :format by default if a format is specified. Of course, if they specify :negative_format, that format is used.
For example:
number_to_currency(-1.23) => "-$1.23"
number_to_currency(-1.23, {:format => "%n %u"}) => "-1.23 $"
number_to_currency(-1.23, {:format => "%n %u", :negative_format => "(%n %u)"}) => "(1.23 $)"The new patch is attached.
-
Andrew White
- State changed from new to open
- Milestone set to 3.0.2
- Assigned user set to Andrew White
Don, since the format is looked up in the locale we should do the same for negative_format. That way you only have to override it in one place. Also can you squash the patch into one commit.
-
Rodrigo Rosenfeld Rosas
I have a client in Brazil that complaint exactly about the negative format used by Rails, so +1!
-
Don Wilson
Andrew, I'll definitely squash the patch into one commit. I realized I had done that after I uploaded it.
I'm not sure what you mean by your other suggestion, though. I agree that the negative_format should also be looked up in the locale. However, if a user specifically passes in a format, I think the negative_format should still be overridden to be the "-" + the format specified regardless of the locale.
Can you explain what you mean?
-
Andrew White
Absolutely the passed option should override the locale format - I just meant that you could specify it in your locale file to override it throughout the application. Could you also do one patch for master and another for 3-0-stable please.
-
Don Wilson
OK, thanks for clarifying that for me. It makes sense now.
I have squashed the patch into one commit and I attached a patch for master and another for 3-0-stable!
-
Andrew White
Don, can you also add some tests to number_helper_i18n_test.rb to test the locale lookup please, so that we don't get any regressions - similar to the tests already there but with negative numbers.
-
Don Wilson
Good idea. I have included new patches with i18n tests!
-
Repository
- State changed from open to resolved
(from [b91371763e1db1c7b7603777e5b18a4da4e09539]) Added :negative_format option to number_to_currency function [#5894 number_to_currency doesn't format negative numbers correctly state:resolved]
Signed-off-by: Andrew White andyw@pixeltrix.co.uk
http://github.com/rails/rails/commit/b91371763e1db1c7b7603777e5b18a... -
Repository
(from [c4d977fbbc31b0a6c7557846f9fe01e688a6f845]) Added :negative_format option to number_to_currency function [#5894 number_to_currency doesn't format negative numbers correctly state:resolved]
Signed-off-by: Andrew White andyw@pixeltrix.co.uk
http://github.com/rails/rails/commit/c4d977fbbc31b0a6c7557846f9fe01... -
Jeff Kreeftmeijer
Automatic cleanup of spam.
-
jackal
very nice pictures is also very lively and attractive you look .every one who wanted to congratulate you You look super. Ankara nakliyat A wonderful picture,nakliyat ankara and always such a special and very attractive as well stay beautiful ok Ankara evden eve nakliyat Ankara nakliye
-
asil
I Agree "However, if a user specifically passes in a format, I think the negative_format should still be overridden to be the "-" + the format specified regardless of the locale."
by antalya hotels -
SEO Company India
It's pretty interesting and informative topic. This is exactly what I was looking for. I shared this post to my Facebook account. Keep up the good work!
