You are here:  » Price format / decimals in price


Price format / decimals in price

Submitted by bird on Wed, 2012-09-26 14:52 in

Hi David,

first of all - thank you very much for this great script!!!

I've got one question concerning the decimals used in the prices. Pricetapestry and some of my data-feed use an english notation even though the prices are in €.
I would like to display prices in the german notation "1.000,00" and not in the english one "1000.00".

I tried to change the function "tapestry_decimalise" in tapestry.php but couldn't figure it out.
Can you give me a hint?

Thank you and best regards
Bernhard

Submitted by support on Wed, 2012-09-26 15:06

Hello Bernhard,

Thank you for your comments and welcome to the forum!

The tapestry_decimalise() function is part of the import process rather than having any effect on the way prices are displayed. It removes things like currency codes from price fields, that sort of thing.

Otherwise, prices are displayed as they are returned by the database - which since they are stored as DECIMAL(10,2) appear in the English notation by default.

There is a single PHP function that will reformat prices to German notation for you - number_format() so you could search and replace in your text editor as follows;

In:

html/featured.php
html/prices.php
html/searchresults.php

Search:

$product["price"]

Replace:

number_format($product["price"],2,",",".")

And in html/product.php

Search:

$mainProduct["price"]

Replace:

number_format($mainProduct["price"],2,",",".")

and also:

Search:

$priceProduct["price"]

Replace:

number_format($priceProduct["price"],2,",",".")

If you're not sure of any of the changes of course just let me know and I'll forward modified files for you.

Hope this helps!
David.
--
PriceTapestry.com

Submitted by bird on Wed, 2012-09-26 15:55

Works perfectly! Thank you very much!

Best regards
Bernhard

Submitted by gunawin on Wed, 2015-05-27 08:29

Hi David,

Is the solution above still valid for 15/01A?
I tried to follow it but no joy

Please help

Cheers,
Win

Submitted by support on Wed, 2015-05-27 08:44

Hello Win,

There is actually a central library function in 15/01 for display of price values so you only need to make one change to affect everywhere that prices are displayed.

So to use the notation of 1.000,00 edit includes/tapestry.php and look for the following code at line 296:

  $price = str_replace(".",$config_currencySeparator,$price);

...and REPLACE with:

  $price = number_format($price,2,",",".");

The order of price / currency symbol if you wanted to change that is now configurable. It defaults to before the price, but if you wanted to display the currency symbol after the price then change line 88 in config.advanced.php as follows;

  $config_currencyHTMLAfter = TRUE;

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by gunawin on Wed, 2015-05-27 16:56

Hi David,

I have modified the code as requested, but now only shows the digit/s before the . dot, for instance: it is showing 1 instead of 1.000 or 15 instead of 15.000

Please help

Cheers,
Win

Submitted by support on Wed, 2015-05-27 18:37

Hello Win,

Sorry about that - I couldn't replicate the outcome I'm afraid so if you could email me your modified includes/tapestry.php and also config.advanced.php I'll check that out for you..

Thanks,
David.
--
PriceTapestry.com

Submitted by gunawin on Wed, 2015-05-27 20:03

Hello David,

All good now, I did some mistakes

Many thanks,
Win