Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Commerce
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
1 Nov 2010 at 13:57 UTC
Updated:
18 Nov 2010 at 19:10 UTC
Jump to comment: Most recent file
Comments
Comment #1
rszrama commentedThanks so much for the patch. I made some minor changes in the name of the function and in that I'm passing in the currency object instead of two separate parameters. I also updated the default currencies array to not include the rounding property any more but just to default that to 0. (And for readability, I changed that property from rounding to rounding_step to conform to the docs. I wonder, too, if "decimals" shouldn't be changed to "precision".)
There were a couple other places that needed to use the commerce_currency_round() function (two Views handlers), though I left the number_format() alone in commerce_price.module with the minor change of loading the currency object and using its actual number of decimals (this was a long-standing TODO item in the comments).
Please let me know if I missed anything or introduced a regression. ; )
I am wondering - should currencies that use the .5 and .2 rounding step also specify decimals => 1? Would you display prices as 95.5 CHF or 95.50 CHF? And I don't see any currencies specifying a 2 for the rounding step... should there be?
Commit: https://github.com/rszrama/drupalcommerce/commit/ea315258cbfa2ea4a317848...
Comment #2
das-peter commentedJust merged - awesome how fast you are with integrating patches :)
I'll let you know if I come across any regression.
Right now the assumption of the rounding function is, that always the last decimal position has to be rounded to the rounding_step - this code handles that
$currency->rounding_step / pow(10, $currency->decimals). Means a combination likerounding_step 5,decimals 2generates e.g. 10.45, but if thedecimalsis set to 1 it would generate 10.5.We could change this to make it
decimalsindependent by definingrounding_stepas decimal instead an integer (E.g. 0.05 for Swiss Francs). This could also lead to a small performance gain, since we could reduce the calculation steps for the$modifier.Frankly speaking I don't know any other currency besides Swiss Francs that has this kind of special rounding. Nevertheless I tried to keep the code as general as possible, just in case... :)
Comment #3
das-peter commentedAttached patch contains:
rounding_stepformat to a decimal representation. Attention: Needs to be defined as string to avoid unpredictable rounding resultscommerce_currency_roundto work with the new property formatcommerce.api.phpwith a detailed description of the currency array. Please review, I doubt that my English is really usable for proper documentation :)Comment #4
rszrama commentedAppears to work just fine, and you read my mind with the language specific caching. : D