Round prices in frontend

ThemeBurn SupportForumsOpenCart ThemesShoppica 2 OpenCart ThemeHow to…Round prices in frontend

How to make prices rounded, without decimals, just in frontend.
And keep backend (admin) with decimals.

For example i have default currency Czech Koruna. which is need to be in XXX.YY format in backend (admin). And in front end it should be XXX format, with out YY.

Thanks a lot.

 neivel
December 19, 2012 at 5:42 pm #16158

Hello;

Go to : system-> Localisation ->currencies
then edit the default or ther currencies by remove the number in “Decimal Places” or make it “0″.

good luck

sam

 samdz
December 19, 2012 at 10:37 pm #16162

Yes thats right, BUT if i put there 0, then invoices not showing decimals, which is must be there.

 neivel
December 20, 2012 at 1:04 am #16165

but, I think that the customer pay what he see, so when customer see XXX he will pay XXX not XXX.YY

 samdz
December 20, 2012 at 7:28 pm #16178

thats a bit tricky, coz in Czech Republic they dont have decimals in prices, but when you calculate VAT it coming with decimals. so stores put rounded prices on their pages, and give you detailed invoice with decimals, which is in the end rounded.

something like that:

  • This reply was modified 4135 days ago by  neivel.
  • This reply was modified 4135 days ago by  neivel.
  • This reply was modified 4135 days ago by  neivel.
  • This reply was modified 4135 days ago by  neivel.
 neivel
December 23, 2012 at 4:58 pm #16332

Hello;

Ok; do this :
open this file:

system/library/currency.php

find this line
$string .= number_format(round($value, (int)$decimal_place), (int)$decimal_place, $decimal_point, $thousand_point);

and replace it by this
$string .= number_format(round($value, 0), (int)$decimal_place, $decimal_point, $thousand_point);

good luck

Sam

 samdz
December 23, 2012 at 11:28 pm #16337

yes, played with it and:

in my case i create second format function in currency.php, and changed sub-total & tax modules and point them to this function.

and result is exactly what i was looking for.

BIG thanks for support!

 neivel
December 24, 2012 at 5:03 am #16347

for sure there is better solution for this, i just dont have enough knowledge to write properly “if-else”.

must be something like:
if (currency = ‘czk’) {
$string .= number_format(round($value, 0), (int)$decimal_place, $decimal_point, $thousand_point);
} else {
$string .= number_format(round($value, (int)$decimal_place), (int)$decimal_place, $decimal_point, $thousand_point);
).

because it shouldn’t affect another currencies.
if you know please help.

 neivel
December 24, 2012 at 5:18 am #16348

Good it works for you.
for using another currencies with CZK currency do this :

if ($currency=='CZK') {
      $string .= number_format(round($value, 0), (int)$decimal_place, $decimal_point, $thousand_point);
        } else {
        $string .= number_format(round($value, (int)$decimal_place), (int)$decimal_place, $decimal_point, $thousand_point);    
        }

good luck

Sam

 samdz
December 24, 2012 at 12:12 pm #16352

Super thanks!

Mark topic as [Solved]

 neivel
December 24, 2012 at 1:58 pm #16354

Hi,

We will move this in the “How to” section :)

BR,
ThemeBurn team

December 27, 2012 at 12:11 pm #16421
Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘How to…’ is closed to new topics and replies.