I've recently setup https://drupal.org/project/uc_bitcoin to accept payments in my Ubercart store using the Bitcoin cryptocurrency.

As such, I'd like to set the Precision on the Currency Format settings up to 8, but currently the only options are 0, 1, 2.

Patch included to allow the Currency Format "Number of decimal places" value on the form to be 0, 1, 2, 3, 4, 5, 6, 7, 8.

I am unsure if there are other consequences, such as database schema or other areas which would need to support this change. I just changed the values available on the Store Configuration form.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nerdcore’s picture

Status: Active » Needs review
FileSize
562 bytes
nerdcore’s picture

Status: Needs review » Needs work

It seems this only partially addresses the desired solution.

I've applied the patch and set the precision for the Currency Format to 8. This appears to work, however when I set a Product's price to "0.12345678" to test, it got rounded to "0.12346000". Where is this rounding coming from? Why 5 decical places?

nerdcore’s picture

I see now that the fields "list_price", "cost", and "sale_price" in the database table uc_products are all set to type "decimal(16,5)".

Could we get this raised to (16,8) instead?

Thanks.

TR’s picture

My feeling is that since this isn't an issue that affects real currencies (all of which have precision 2 or less) it should be done in uc_bitcoin if at all possible. If we allow higher precisions, then people will start using them because of course everyone wants the best precision, but I'm positive that will cause its own set of problems.

I think if you write a hook_form_alter() for the uc_bitcoin module you can modify the store settings form to allow higher precisions for when the store currency is bitcoin. The precision is used for display purposes only, so alternatively you could override some theme functions to do the same thing. If you want your store currency to be bitcoin, you would also have to write a hook_update_N() to alter the database schema, as you discovered. But all this could be done in uc_bitcoin.

But do you really want the store currency to be set to bitcoin, as opposed to using a normal currency and just accepting payment in bitcoins? uc_bitcoin is a payment gateway. Using bitcoin as a store currency presents problems other than display; because the bitcoin exchange rate fluctuates wildly you will still need some way to dynamically adjust all your prices, won't you? Or do you really want prices fixed to fractional bitcoins?

nerdcore’s picture

Status: Needs work » Needs review
FileSize
2.3 KB

I would like an Ubercart store which operates solely in BTC and has no relation to values in what you call "normal" currencies.

I'm a bit perplexed why the database schema already allows for 5 decimal places when the UI only offers choices in the range 0-2.

Attached is a patch which includes #2 but also alters the database schema in the uc_product module to increase the three price fields in the uc_products table from decimal(16,5) to decimal(16,8).

TR’s picture

We need extra places to account for rounding and to make sure that taxes get calculated properly.

longwave’s picture

I am also wary of making this change in core as I do not want to introduce any further rounding problems, and it's not even needed for all stores that accept Bitcoin - only ones that actually price their items in BTC. However this looks like it is all solvable via hook_form_alter, hook_schema_alter and maybe a few others. Therefore my suggestion is to add a uc_bitcoin_store or similar submodule to your project that alters the price fields and settings forms in order to achieve this.

longwave’s picture

Status: Needs review » Closed (won't fix)