Revindex Storefront

Export Print

How numbers are calculated and rounded

Internally, the Storefront uses 4 decimal precision places to store and calculate numeric values. Using 4 decimal places allows greater precision to handle extremely price sensitive commodities such as jewelry, industrial chemicals, pharmaceutical drugs, manufacturing goods, etc. where amounts may need to be multiplied by fractional unit cost (e.g. $1.0381 per gram). 

In addition, the higher level of precision allows for more accurate calculation of the total amount than typical 2 decimal places calculations. Suppose your business sells ceramic tiles at $10.00 each and you're giving a 1/3 discount for each item ordered in your store. The Storefront will calculate a fractional discount of $3.3333 per unit. If the customer orders 100 ceramic tiles, it will yield a total discount of $333.33. If the system had used a 2 decimal place precision, it would have calculated a less accurate total discount of $333 and the customer is overcharged by $0.33.

Even though using 4 decimal places internally is important for accurate calculation, it is customary for businesses to round the final amount to display 2 decimal places to accommodate the country's monetary system. Internally the values are always calculated with 4 decimal places without rounding, but the values shown on screen are rounded to 2 decimal places by the Storefront before being displayed. So even if you sell a product that has a fractional amount and the customer places 1000 items in the cart, the total sum will always be highly accurate. In contrast, where it would be wrong is if the Storefront had rounded it early during the discount calculation and later perform the sum of the total amount towards the end of the mathematical flow, the sway would be amplified by the number of items in the cart.

The rounding strategy follows your system's rounding algorithm and commonly follows the "Banker's rounding" algorithm:

  • any fractional number less than 5 will round down to the previous nearest number
  • any fractional number greater than 5 will round up to the next nearest number 
  • the fractional 5 itself will round up or down to the nearest even number (e.g. 1.745 will round down to 1.74 whereas 1.755 will round up to 1.76).

The Banker's rounding algorithm is considered more accurate and fair because it doesn't favor any side, and is preferred by bankers and accountants. In particular, the fractional 5 is evenly rounded up or down by perfectly half case.


Add comment

Powered by Revindex Wiki