Page 1 of 1
Automatically remove decimal places in price for product
Posted: Thu Dec 29, 2016 12:48 am
by pla1829
I saw a post here:
viewtopic.php?f=20&t=42133
It recommends to hide the .00 when it is .00 and only show decimals when they are needed (ie: .68) to change the following code in system/library/currency.php:
Into:
Code: Select all
return str_replace('.00','',$string);
I did a quick search in OpenCart 2.3.0.2 and noticed it does not have a system/library/currency.php
How does one go about making such a modification in OpenCart 2?
Re: Automatically remove decimal places in price for product
Posted: Thu Dec 29, 2016 1:22 am
by opencartmart
In OC 2.3.0.2, currency.php is located at system/library/cart/currency.php
Re: Automatically remove decimal places in price for product
Posted: Thu Dec 29, 2016 1:29 am
by pla1829
Thanks
Re: Automatically remove decimal places in price for product
Posted: Fri Feb 01, 2019 5:09 pm
by motion2082
This works but it only strips “.00” if you have “.37” or “.04” etc it won’t strip out the decimal. Anyone know how to do that?
Re: Automatically remove decimal places in price for product
Posted: Fri Feb 01, 2019 6:24 pm
by kestas
You can use round function to your choice...
Code: Select all
return round($string, 0, PHP_ROUND_HALF_UP);
below examples ho to be rounded if you use some of this functions...
Code: Select all
echo round(9.5, 0, PHP_ROUND_HALF_UP); // 10
echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9
echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10
echo round(9.5, 0, PHP_ROUND_HALF_ODD); // 9
echo round(8.5, 0, PHP_ROUND_HALF_UP); // 9
echo round(8.5, 0, PHP_ROUND_HALF_DOWN); // 8
echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8
echo round(8.5, 0, PHP_ROUND_HALF_ODD); // 9
Re: Automatically remove decimal places in price for product
Posted: Fri Feb 01, 2019 8:08 pm
by motion2082
kestas wrote: ↑Fri Feb 01, 2019 6:24 pm
You can use round function to your choice...
Code: Select all
return round($string, 0, PHP_ROUND_HALF_UP);
below examples ho to be rounded if you use some of this functions...
Code: Select all
echo round(9.5, 0, PHP_ROUND_HALF_UP); // 10
echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9
echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10
echo round(9.5, 0, PHP_ROUND_HALF_ODD); // 9
echo round(8.5, 0, PHP_ROUND_HALF_UP); // 9
echo round(8.5, 0, PHP_ROUND_HALF_DOWN); // 8
echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8
echo round(8.5, 0, PHP_ROUND_HALF_ODD); // 9
Thanks for the tip but that just hides the prices for me
I have a rounding extension installed already
Problem is I can't purchase items without 2 decimals showing with NAB
If I set it to 0 decimals it takes the money but returns a fingerprint mismatch error