Tierprice decimals display
سؤال
I am trying to display all prices with 4 decimals (i know a little bit weird but the customer demanded this). I have overwritten Mage/Core/Store, changed the currency.php precision in the Zend lib and adjusted Mage_Directory_Model_Currency.
In the backend, all my prices are displayed correctly but in the frontend i receive a price rounded to 2 decimals followed by 00. Especially the tier price is very crucial.
Since i dont have any knowledge in pricing i have tried some tutorials on Magento Forum with no success. I also tried 2 extensions with no luck.
Any help?
المحلول 3
I decided not to do it and adviced the customer to refrain from pushing it because I could not get any exact results. As mentioned in the comments:
4 decimal precision is inherently imprecise in Magento.
نصائح أخرى
I think you'll find what you need in the format
method inside app/code/core/Mage/Directory/Model/Currency.php
.
/**
* Format price to currency format
*
* @param double $price
* @param bool $includeContainer
* @return string
*/
public function format($price, $options=array(), $includeContainer = true, $addBrackets = false)
{
return $this->formatPrecision($price, 2, $options, $includeContainer, $addBrackets);
}
I had to completely rewrite my template's price.phtml
anyway, and I used
<?php printf("$%.2f", $_finalPrice) ?>
so you could do the same but with %.4f
Also, if needing to perform comparisons on floats, I recommend:
if( abs($_price1 - $_price2) < .0001 )
instead of if($_price1 == $_price2)
Sometimes, php's type flexibility induces unexpected errors, so explicit casting to your desired data type is often needed: $margin=(float)1-$margin;
I have gotten to where I don't even try to stack multiple math operations into one line of code.