6

My Magento2 is ver. 2.2.0-dev. When I set product's price to $0.68, after save the price will be $0.68000000000000005. But when the price is $0.5, it's ok.

  • have you checked this in an official/stable release, e.g. v2.1.6? Maybe it's a 2.2.0 development bug – juhanix May 29 '17 at 8:10
1

Within the 2.2.0-dev 'app/bootstrap.php' there are below lines. The precision sets the number of decimal places being used by php so setting this to 2 should change the decimal places used:

/*  Adjustment of precision value for several versions of PHP */
ini_set('precision', 17);
ini_set('serialize_precision', 17);

Change to:

/*  Adjustment of precision value for several versions of PHP */
ini_set('precision', 2);
ini_set('serialize_precision', 2);

You could also set the price variable to show just 2 decimal places with below from within your template:

echo number_format($product->getPrice(), '2', '.', ',')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.