Consistent Format of Prices - 2 Decimal Places

Highlighted
New Member
6 0 0

Hi,

My store uses the Brooklyn theme and my shop is configured to use the default United States Dollars format (e.g. "{{amount}}") in Settings - General.

If a product's price or "compare at price" is a whole number (e.g. 1234.00), it will be displayed without decimals (e.g. $1,234) where as other amounts include two decimal placess (e.g. $1,234.50). This behavior can be found in collection and product pages but not the cart or checkout pages.

I'd like to make the display of prices consistent, having two decimal places. Does anyone know how to do this? Thank you in advance.

Regards,
Mickey

0 Likes
Highlighted
Astronaut
1890 1 442

Open Snippets/product-grid-item.liquid.  Search for money_without_trailing_zeros and replace it with money.

            {{ product.price_min | money_without_trailing_zeros }}
            {{ product.price_min | money }}

            {{ product.price | money_without_trailing_zeros }}
            {{ product.price | money }}

Open Assets/timber.js.liquid.  Search for .replace(/((\,00)|(\.00))$/g, '')) and delete it.

    $productPrice.html(Shopify.formatMoney(variant.price, moneyFormat).replace(/((\,00)|(\.00))$/g, '')).show();
    $productPrice.html(Shopify.formatMoney(variant.price, moneyFormat)).show();

      $comparePrice.html(Shopify.formatMoney(variant.compare_at_price, moneyFormat).replace(/((\,00)|(\.00))$/g, ''));
      $comparePrice.html(Shopify.formatMoney(variant.compare_at_price, moneyFormat));

I hope this helps.

Edit: fixed code

Highlighted
New Member
6 0 0

(see next post) Thank you. This worked perfectly.

0 Likes
Highlighted
New Member
6 0 0

Whoops! I answered too quickly. These changes made my navigation menu disappear. I undid the changes to Assets/timber.js.liquid and the menu reappeared but so did the original behavior.

Could it be that there was an extra ")" that I shouldn't have deleted?

0 Likes
Highlighted
Astronaut
1890 1 442

Yes, you're right.  Sorry about that!  Try this:

    $productPrice.html(Shopify.formatMoney(variant.price, moneyFormat).replace(/((\,00)|(\.00))$/g, '')).show();
    $productPrice.html(Shopify.formatMoney(variant.price, moneyFormat)).show();

      $comparePrice.html(Shopify.formatMoney(variant.compare_at_price, moneyFormat).replace(/((\,00)|(\.00))$/g, ''));
      $comparePrice.html(Shopify.formatMoney(variant.compare_at_price, moneyFormat));

 

Highlighted
New Member
6 0 0

Perfect! Thank you so much for helping me again!

0 Likes
Highlighted
New Member
2 0 1

Hey, this file is not here in my Prestige theme. So now what do I do? 
I want to add to the price of the product page.  

 

Highlighted
New Member
1 0 0

Hello, this solution doesn´t help me with my Narrative Theme. Please help. I would like to have consistent prices with 2 decimals as well.

0 Likes