News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

How to get rid of trailing zeros in product prices in cart module?

Started by borro, July 13, 2015, 14:04:21 PM

Previous topic - Next topic

borro

Hello.

Is there any setting to turn off the trailing zeros in product prices showed in a VM cart module?

Virtuemart 3.0.9

Answer:
Go to \administrator\components\com_virtuemart\helpers\currencydisplay.php and in definition of public function getFormattedCurrency after the row:
$res = number_format((float)$nb,(int)$nbDecimal,$this->_decimal,$this->_thousands);
insert this one:
$res = str_replace(",00", "", $res);
Wish you happiness!

escozul

I found a much better solution which works with products that might or might not have trailing zeros.

So you might have one product that costs 25.85 another that costs 10.80 and another that is 34.00

They should be 25.85 € and 10.8 € and 34 €.

To do that you should go and take the file in
\administrator\components\com_virtuemart\helpers\currencydisplay.php

and then edit it. Go to the line that has the following code:
$res = number_format((float)$nb,(int)$nbDecimal,$this->_decimal,$this->_thousands);

it's about 288th line
and below that add the following 2 lines:

$res = rtrim($res, "0");
$res = rtrim($res, ",");


That way you only trim the trailing zeros. You might only need to remove one zero and keep the decimal point.

I used comma as a decimal point but you might need to change the second line to remove the point (.) instead. Depends on your localization settings.

Hope that helped.

Now I would like to know if there is a way to make an override in the templates/[template name]/html/com_virtuemart folder structure, to avoid changing the core file structure.
Does anyone know where that would work?

creating a folder helpers inside templates/[template name]/html/com_virtuemart did not work for me.

Thank you.