Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 3
How do I use more than two decimal places for prices? 
 
jgonzalez
Jr. Member
 
Total Posts:  11
Joined:  2008-08-27
Castelldefels
 

Hi there,

I want to sell stationery in great quantities, and I want to have prices per unit with more than two decimal places with tier pricing. For example:

Up to 1.000 business cards: 0,100€
Up to 2.000 business cards: 0,095€
Up to 3.000 business cards: 0,093€

The final price should be computed from these prices and then rounded to two decimal places for invoicing.

I’ve noticed that if I introduce prices in the backend with more than two decimal places those prices are correctly stored in the database. The problem is that those prices reflect neither in the frontend nor in the backend…

In the frontend the prices are shown rounded to two decimal places, so option 2 and 3 show the same price. In the backend prices are also shown rounded to two decimal places, so if I load a product with previously correct prices in the database and then save the product the prices are stored rounded in the database.

This seems to be just a presentation related problem, as the database seems to be able to store the prices correctly. Is there any way to fix this?

Thanks in advance, best regards

 
Magento Community Magento Community
Magento Community
Magento Community
 
jgonzalez
Jr. Member
 
Total Posts:  11
Joined:  2008-08-27
Castelldefels
 

Amy idea?

 
Magento Community Magento Community
Magento Community
Magento Community
 
marito
Jr. Member
 
Total Posts:  14
Joined:  2008-09-02
 

In line 62 in /lib/zend/Currency.php you can change the precision for all prices in your shop.

protected $_options = array(
        
'position'  => self::STANDARD,  // position for the currency sign
        
'script'    => null,            // script for output
        
'format'    => null,            // locale for numeric output
        
'display'   => self::NO_SYMBOL// currency detail to show
        
'precision' => 0,               // precision for currency
        
'name'      => null,            // name for this currency
        
'currency'  => null,            // 3 lettered international abbreviation
        
'symbol'    => null             // currency symbol
    
);
I hope, this will help you…
 
Magento Community Magento Community
Magento Community
Magento Community
 
Kjarnakall
Jr. Member
 
Total Posts:  27
Joined:  2008-07-14
Iceland
 

In line 62 in /lib/zend/Currency.php you can change the precision for all prices in your shop.

protected $_options = array(
        
'position'  => self::STANDARD,  // position for the currency sign
        
'script'    => null,            // script for output
        
'format'    => null,            // locale for numeric output
        
'display'   => self::NO_SYMBOL// currency detail to show
        
'precision' => 0,               // precision for currency
        
'name'      => null,            // name for this currency
        
'currency'  => null,            // 3 lettered international abbreviation
        
'symbol'    => null             // currency symbol
    
);
I hope, this will help you…

Thanks Marito, wouldnt have found it…

Kv. Kjarnakall

 
Magento Community Magento Community
Magento Community
Magento Community
 
mixleplix
Jr. Member
 
Total Posts:  3
Joined:  2008-10-21
 

Hello,

I changed the precision to 3, and that displays on the frontend with 3 decimals.

However, when in the admin and setting prices in the Tiers, I set to 0.024, 0.026 etc and it is rounding the number up throughout the admin and what is used in the front end.

The database is 4 decimals and that is showing correctly in the DB to what I set, however by the time it makes it to screen it is rounded.

Can someone point out the flow of money for this

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
mixleplix
Jr. Member
 
Total Posts:  3
Joined:  2008-10-21
 

Ok i found the location of problem 1: rounding to 2 decimals on calculations

on file:
/app/code/core/Mage/Core/Model/Store.php

Change the roundPrice function to:

public function roundPrice($price,$roundTo=3)
    
{
    
return round($price$roundTo);
    
}

That sets it to 3 on EVERYTHING (assuming you chanced the precision to 3 as stated above on the Zend/Currency.php file.

The next step is to distinguish which numeric variables should display 3 and which should do 2. Right now it is all or nothing.

 
Magento Community Magento Community
Magento Community
Magento Community
 
brokenseal
Jr. Member
 
Total Posts:  9
Joined:  2008-05-28
 

For anyone who is still interested in this topic, I found the place where you can let the admin get more than 2 decimal places.

You can find it here: app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Options/Option.php line 284

Cheers.

 
Magento Community Magento Community
Magento Community
Magento Community
 
dalberts69
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-12-03
 

Howdy…

I’ve also found a way to change the tier pricing setup in the Admin to accept 3 or more decimal places…

\app\design\adminhtml\default\default\template\catalog\product\edit\price\tier.phtml

Line 118

Change:

<?php echo sprintf('%.2f'$_item['price']?>

to

<?php echo sprintf('%.3f'$_item['price']?>

Or change the 2 to 3 or 4 etc.

Seems to work so far…

 
Magento Community Magento Community
Magento Community
Magento Community
 
tdmedia
Jr. Member
 
Total Posts:  2
Joined:  2008-10-30
 

Just wanted to add that as of 1.3.2.3 I had to edit app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php

at the very bottom of the file

return number_format($value4null'');

In this case to get the admin screen to show the full four decimal places that I wanted. I did this in addition to the other two fixes listed above.

Thanks to all who posted before me!

 
Magento Community Magento Community
Magento Community
Magento Community
 
deanbeasley
Jr. Member
 
Total Posts:  5
Joined:  2008-12-08
 

and v 1.2.1.2 uses this location too

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jason J
Sr. Member
 
Total Posts:  79
Joined:  2008-05-29
 

I’m wondering if this still applies to the latest Magento (January 2010)? I asked the question here for follow-ons:

http://www.magentocommerce.com/boards/viewthread/74674/

-- Jason

 
Magento Community Magento Community
Magento Community
Magento Community
 
pmjacob
Jr. Member
 
Total Posts:  4
Joined:  2010-03-04
 

if you want to have 3 decimal places in custom product option you should change

/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php

public function getPriceValue($value$type)
    
{
        
if ($type == 'percent'{
            
return number_format($value3null'');
        
elseif ($type == 'fixed'{
            
return number_format($value3null'');
        
}
    }
 
Magento Community Magento Community
Magento Community
Magento Community
 
AnshumaanBakshi
Member
 
Avatar
Total Posts:  33
Joined:  2008-11-14
Delhi, India
 

I have tried solution by mixleplix, I think it’s the best one.

Thanx
AB

 
Magento Community Magento Community
Magento Community
Magento Community
 
Petralian
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2009-09-03
Hong Kong
 

For v1.4+

1. Copy the file
/app/code/core/Mage/Core/Model/Store.php

to
/app/code/local/Mage/Core/Model/Store.php (you will probably need to create most of the directories)

By copying this file from core to local you just made this file Magento update proof… in other words, when you update your Magento installation it will keep on using the file you made.

2. Example: Change from 2 decimals to 1 decimal…
Find, then change the return round number (line 740) from 2 to 1 as shown below.

public function roundPrice($price)
    
{
        
return round($price1);
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
luksy
Jr. Member
 
Total Posts:  2
Joined:  2010-02-03
 

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
 
sophy_b
Jr. Member
 
Total Posts:  3
Joined:  2008-11-06
 

Hi,

To get 3decimals accurancy for all prices in magento 1.4

In /lib/Zend/Currency.php line 78

'precision' => 3,

Override in app/code/locale the Mage core files and make some changes :

Mage/Core/Model/Store.php line 738

public function roundPrice($price)
    
{
        
return round($price3);
    
}

Mage/Directory/Model/Currency.php line 195

public function format($price$options=array(), $includeContainer true$addBrackets false)
    
{
        
return $this->formatPrecision($price3$options$includeContainer$addBrackets);
    
}

Hope that helps !

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