Magento Forum

   
Page 2 of 3
How do I use more than two decimal places for prices? 
 
sepp
Sr. Member
 
Avatar
Total Posts:  120
Joined:  2008-06-14
Hamburg
 

here all the files to be changed

/app/code/core/Mage/Core/Model/Store.php
line 740
return round($price, 2);
Change to:
return round($price, 4);
---------------------------------------------------------------------------------------------------------------
\app\design\adminhtml\default\default\template\catalog\product\edit\price\tier.phtml
line 161
‘<?php echo sprintf('%.2f', $_item['price']) ?>’
Change to:
‘<?php echo sprintf('%.4f', $_item['price']) ?>’
-----------------------------------------------------------------------------------------------------------------
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php
line 86
return number_format($value, 2, null, ‘’);
Change to:
return number_format($value, 4, null, ‘’);
--------------------------------------------------------------------------------------------------------------
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php
line 285

if ($type == ‘percent’) {
return number_format($value, 2, null, ‘’);
} elseif ($type == ‘fixed’) {
return number_format($value, 2, null, ‘’);
Change to:
if ($type == ‘percent’) {
return number_format($value, 4, null, ‘’);
} elseif ($type == ‘fixed’) {
return number_format($value, 4, null, ‘’);

If you updates to 1.4.1.0, everything is gone
then you have to change it again

 
Magento Community Magento Community
Magento Community
Magento Community
 
ceefour
Member
 
Avatar
Total Posts:  52
Joined:  2008-09-16
Bandung, Indonesia
 

Thank you very much luksy!

Your code works excellently!

luksy - 26 May 2010 05:53 PM

If you have multiple currencies, format() in Mage_Directory_Model_Currency overrides the precision, by passing a new precision that ends up overwriting the default precision specified in Zend_Currency

solution:

copy

/app/code/core/Mage/Directory/Model/Currency.php

to

/app/code/local/Mage/Directory/Model/Currency.php

and change the second argument passed to formatPrecision on line 197 to your desired precision (default 2)

return $this->formatPrecision($price2$options$includeContainer$addBrackets);

This sets precision for all currencies though, so it is also possible to add a small function to set precision for individual currencies, like

public function format($price$options=array(), $includeContainer true$addBrackets false)
    
{
        
($this->getCurrencyCode() == "JPY") ? $precision $precision 2;
        return 
$this->formatPrecision($price$precision $options$includeContainer$addBrackets);
    
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
tPl0ch
Jr. Member
 
Total Posts:  2
Joined:  2010-05-27
 

app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php
line 285

if ($type == 'percent'
    
return number_format($value2null''); 
elseif ($type == 'fixed'
    
return number_format($value2null''); 
}

This is an almost idiotic code snippet.

Why do you need a condition if you return the same thing anyway?

Oh my Magento…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rito
Jr. Member
 
Total Posts:  6
Joined:  2010-06-07
 

@sepp

works good in 1.4.1. But ist there a way to show decimals even in invoice?

greetz
Rito

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mazedia development team
Jr. Member
 
Total Posts:  1
Joined:  2010-06-02
 

Apparently Magento 1.4.1.1 calculates with a rounded price for line totals and grand totals! If you’re working with prices with more than 2 decimals, you might run into a calculation issue.
For instance my client had given me a total price for 3 products of 56,00 euros, when applied as a tier price of 18,6666 euros that gave me a line total of 56,01 euros. Which is obviously not what I wanted.

To fix this you might consider fixing the ‘Mage/Core/Model/Store.php and comment out rounding the price in the price conversion :

/**
     * Convert price from default currency to current currency
     *
     * @param   double $price
     * @param   boolean $format             Format price to currency format
     * @param   boolean $includeContainer   Enclose into <span class="price"><span>
     * @return  double
     */
    public function convertPrice($price$format=false$includeContainer true)
    
{
        
if ($this->getCurrentCurrency() && $this->getBaseCurrency()) {
            $value 
$this->getBaseCurrency()->convert($price$this->getCurrentCurrency());
        
else {
            $value 
$price;
        
}
        
// XXX avoid calculating with a rounded price! This is a very bad habit! $value = $this->roundPrice($value);

        
if ($this->getCurrentCurrency() && $format{
            $value 
$this->formatPrice($value$includeContainer);
        
}
        
return $value;
    
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
ZetaWorks
Jr. Member
 
Total Posts:  30
Joined:  2010-09-21
 

Hello i have a problem with this.
I tried all combinations with the files all users posted before but i have still some errors.
I tried to modify the database using the magento guide: http://www.magentocommerce.com/wiki/groups/138/fix_decimal_price_bug
But there is something wrong so i can\’t do all the steps of the guide: exactly i can\’t run this line command:

insert into catalog_product_entity_int (entity_type_idattribute_id,   store_identity_idvalue)
Mysql answers with a parse error caused by the version of mysql. (I USE MYSQL 5+). Maybe the syntax of that line isn\’t right for the version of mysql i use.

Anyway using some steps of that guide and modifying the file \\app\\code\\core\\Mage\\Directory\\Model\\Currency.php
changing the second argument passed to formatPrecision on line 197 to 4

Now i see the decimal but the price is not correct. Now the price has more 0, for example 85,00 now is 85,000. How can i do?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mundola
Jr. Member
 
Total Posts:  10
Joined:  2010-11-23
 

Hi guys

How do I remove the decimal places?

I need to show £89.00 as just £89.

Please help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jaco Wang
Jr. Member
 
Total Posts:  20
Joined:  2010-09-17
 

i modifiy all the files listed above, but it doesn’t work in version 1.5.0.1? any advice?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jolandi
Jr. Member
 
Total Posts:  7
Joined:  2008-06-27
 

@ Mundula: Maybe you should check this extension: Price Layout (Web and People)
http://www.magentocommerce.com/magento-connect/WebAndPeople/extension/4428/wp_price_decimal

@ All: If you want to have more than two decimal places for BUNDLE prices, you also need to change this file:

app\design\adminhtml\default\default\template\bundle\product\edit\bundle\option\selection.phtml

Around line 124 change:
data.selection_price_value = Number(data.selection_price_value).toFixed(2);
into:
data.selection_price_value = Number(data.selection_price_value).toFixed(4);
to have 4 decimals also there.

In Magento 1.5x it works with the prior changes (you can enter 4 decimal) but, after saving you just can see only first 2. So this step is not necessary, but more easy if you want to check prices for bundled products grin

By the way - the prices are stored into “catalog_product_bundle_selection” (DB) just if someone need that information, too.

 
Magento Community Magento Community
Magento Community
Magento Community
 
palanikumark
Member
 
Total Posts:  66
Joined:  2010-01-03
 

More than two decimal places for prices. Hope this will help you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ElsonSolano
Member
 
Total Posts:  34
Joined:  2011-06-02
 

Is there a way to only set up the Unit Price having a 3 decimal places? Only the Unit Price but others will be the same.

Because I have a Unit Price 0.105 and when I ordered 500 in QTY, the result would be 52.500, I only want it to be displayed 52.50

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
cschuler
Jr. Member
 
Total Posts:  3
Joined:  2011-06-23
 
ElsonSolano - 09 August 2011 05:01 PM

Is there a way to only set up the Unit Price having a 3 decimal places? Only the Unit Price but others will be the same.

Because I have a Unit Price 0.105 and when I ordered 500 in QTY, the result would be 52.500, I only want it to be displayed 52.50

Thanks!

I’m looking for the same thing.  I only want the UNIT price to have 4 decimal places. Total prices should round to 2 decimal places.

i.e. Unit Price = $0.0446 .... QTY=10225 .... Price = $456.04 (NOT $456.0350 )

Have any luck getting this to work?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ashishkhadpe
Member
 
Total Posts:  50
Joined:  2011-08-22
 

Open code/core/Mage/Directory/Model/Currency.php
on line no 194
public function format($price, $options=array(), $includeContainer = true, $addBrackets = false)
{
return $this->formatPrecision($price, 2, $options, $includeContainer, $addBrackets);
}
2-Denotes the precision point for price..
Blog Link : Magento Coders

 
Magento Community Magento Community
Magento Community
Magento Community
 
Evenshop
Jr. Member
 
Total Posts:  26
Joined:  2008-04-06
 

I would like to hide the decimal when it’s not necessary.

For example if the price is 90,00$ I would like to display only 90$

But if the price is 90,99$ I would like to display 90,99$

Any way to do it?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bannerstands
Jr. Member
 
Avatar
Total Posts:  2
Joined:  2011-11-16
 

I think it looks much neater to have prices displayed without decimal places. For example £99 reads better than £99.99 for me anyway

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 2 of 3