After upgrading to the latest dev release, prices in product node edit files have 3 decimal places...
odd.

Comments

yesct’s picture

StatusFileSize
new32.44 KB
new30.61 KB

here are a before and after screen shot of the edit product node.

I print out the price in a bunch of places with this code:

  $my_product_node = node_load('5');
  echo "e-book $"; 
  print $my_product_node->sell_price;
 

.... and it is printing out with 3 decimal places now... looks odd.

Island Usurper’s picture

Status: Active » Closed (works as designed)

This was done to allow modules that control the price of products more accuracy when multiplying percentages. European stores, for example, have to display the price with the VAT included, and without 3 decimal places, they can't always set the price to the exact amount they want.

Use uc_currency_format() or possibly number_format() when displaying prices.

yesct’s picture

Ah! Thanks!

asak’s picture

And how can this be fixed in the node edit form... ?

rszrama’s picture

Status: Closed (works as designed) » Needs work

I just found out in development on another module that if you use PHP's round(), it will strip off trailing 0's. So, in places like the product edit form, why don't we just apply round() to the default value of textfields to the maximum number of decimal places? Then instead of 13.820 you'd see 13.82.

yesct’s picture

Wouldn't you also see $11.1 instead of $11.10?

rszrama’s picture

Issue tags: +price, +ubercamp sprint

Tagging.

Island Usurper’s picture

Status: Needs work » Closed (works as designed)

Rounding would throw off all of the prices that actually need to be stored with three decimal places.

rszrama’s picture

Status: Closed (works as designed) » Needs work

I'm not sure why. There's a setting in the store format settings where you can specify "Number of decimal places." Perhaps we just need to enhance / use that field, but if it's configurable then someone who needs 3 decimal places on a node form could adjust that when they setup their currency format. It doesn't have to affect any storage or any other fields... perhaps it could be split up into number of places for display and a separate for data entry. Make sense?

xibun’s picture

+1 (for my shop I would set "Number of decimal places for display" = 2 and "Number of decimal places for data entry" = 5)

xibun’s picture

was just thinking about this again... in case you want to make this configurable I would even go a step further:
in order to reduce future support requests it should have a good setting out of the box which will not produce rounding errors (i.e. 5 decimal places in the database) but not confuse administrators unnecessarily (only show them 2 decimal places by default).

therefor I now see the following settings:
"Number of decimal places for display in the shop" (default = 2, range = 0-3 [3 is a potential solution to the rounding problem in countries with 20% VAT rate such as Austria and others])
"Number of decimal places for display to the admin" (default = 2, range = 0-6 [admin should be able to edit the full precision of prices in the db])
"Number of decimal places for database" (default = 5, range = 0-6 (6 solves a special case for the reduced VAT rate in France)

the last setting could actually be hardcoded to 5 (or even 6, but that case is really rare).

rszrama’s picture

Issue tags: +Release blocker

This is related to #479784: Order rounding.

Island Usurper’s picture

Status: Needs work » Needs review
StatusFileSize
new1.82 KB

Deciding how many decimal places are actually stored is mostly up to the database. I think that decision is for #479784 like Ryan said. This issue is about how many are displayed on the node edit form, which is only somewhat related to the number of decimal places displayed everywhere else on the site.

Patch removes any trailing zeros down to the last two decimal places. It considers 6 decimal places to be the "exact" value that was entered, since it sounds like that's the most any monetary application ever needs.

xibun’s picture

Nice solution. It works for me as expected when I disable the VAT module.

Question: can we use the same formating rules for "Cost" & "Price" on the edit options page?
EDIT: and maybe also when displaying the default on edit attributes? re-EDIT: on second thought it probably doesn't make sense for the default values, as the customer also only will see 2 digits.

Island Usurper’s picture

Status: Needs review » Fixed
StatusFileSize
new3.38 KB

Yeah, that makes sense to do the same thing for attributes. New patch includes those changes.

It looks good from here as well, so it's committed. Thanks for the review.

Status: Fixed » Closed (fixed)
Issue tags: -Release blocker, -price, -ubercamp sprint

Automatically closed -- issue fixed for 2 weeks with no activity.