Shopify invalid floating point number in property price

When working with multiple Shopify Markets, with different currencies in some of the markets, you may find you that get the following error in Google Search Console > Merchant Listings: shopify Invalid floating point number in property “price” (in “offers”).

This is a problem stemming from the way rich snippet microdata is generated on Shopify.

Shopify invalid floating point number in property price

There are two main reasons this might appear:

  1. Price snippet field contains currency symbol, e.g. “ยฃ8.99”
  2. Price snippet field contains a comma or other non-point separator, e.g. “8,99”

As the solution to shopify Invalid floating point number in property “price” (in “offers”), I used part of the following microdata code:

{%- capture main_entity_microdata -%}
“@type”: “Product”,
“offers”: {
“@type”: “Offer”,
“availability”: {%- if product.available -%}”https://schema.org/InStock”{%- else -%}”https://schema.org/OutOfStock”{%- endif -%},
“price”: {{ product.price | divided_by: 100.0 }},
“priceCurrency”: {{ cart.currency.iso_code | json }},
“priceValidUntil”: {{‘now’ | date: ‘%s’ | plus: 100000 | date: ‘%d-%m-%Y’ | uri_encode | replace: ‘+’, ‘%20’ | json}},
“url”: “{{ shop.url }}{{ product.url }}”
},
“brand”: {
“@type”: “Brand”,
“name”: {{ product.vendor | json }}
},
“sku”: “{{ product.id }}”,
“gtin13”: “{{ product.variants.first.barcode }}”,
“name”: {{ product.title | json }},
“description”: {{ product.description | strip_html | json }},
“category”: {{ product.type | json }},
“url”: “{{ shop.url }}{{ product.url }}”,
“image”: {
“@type”: “ImageObject”,
“url”: “https:{{ product.featured_image | img_url: ‘1024×1024’ }}”,
“image”: “https:{{ product.featured_image | img_url: ‘1024×1024’ }}”,
“name”: {{ product.featured_image.alt | json }},
“width”: 1024,
“height”: 1024
}
{%- endcapture -%}

Specifically this line was the main line to get right:

“price”: {{ product.price | divided_by: 100.0 }},

This takes the price (in cents/pence e.g. 895 (ยฃ8.95) and returns it as 8.95.

I was previously using “price”: {{ product.price | money_without_currency | replace: ‘,’, ‘.’ | json }}, to strip the currency symbol and replace the commas, but this was returning a string, which validated, but isn’t very future proof. Kudos to Barry on google support forums for putting that straight.

NOTE: If your Shopify theme uses a different word from “product”, you’ll need to adjust that accordingly.

The other line that might interest users of Shopify Markets is:

“priceCurrency”: {{ cart.currency.iso_code | json }},

This uses the currency that the page is being accessed in, so if you are using sub-folders for different markets, and currency switching, e.g. /en-fr/products/product_name, then it ensures the currency matches up properly. So this is instead of using “shop.currency”.

So, a pretty simple solution to the error you might get with Shopify invalid floating point number in property “price” (in “offers”).

I’m assuming you already have a microdata snippet, but if not, you can add it in the Shopify Theme > Edit Code > Add Snippet and then call it from your theme.liquid file. Note that I’ve used gtin13, so if your barcodes are not 13chars, then adjust that bit.

Here’s the full snippet I’m using:

{%- comment -%}This snippet structures the micro-data using JSON-LD specification{%- endcomment -%}

{%- if template.name == ‘product’ -%}
{%- capture main_entity_microdata -%}
“@type”: “Product”,
“offers”: {
“@type”: “Offer”,
“availability”: {%- if product.available -%}”https://schema.org/InStock”{%- else -%}”https://schema.org/OutOfStock”{%- endif -%},
“price”: {{ product.price_min | money_without_currency | json }},
“priceValidUntil”: {{‘now’ | date: ‘%s’ | plus: 100000 | date: ‘%d-%m-%Y’ | uri_encode | replace: ‘+’, ‘%20’ | json}},
“priceCurrency”: {{ shop.currency | json }},
“url”: “{{ shop.url }}{{ product.url }}”
},
“brand”: {
“@type”: “Brand”,
“name”: {{ product.vendor | json }}
},
“sku”: “{{ product.id }}”,
“gtin13”: “{{ product.variants.first.barcode }}”,
“name”: {{ product.title | json }},
“description”: {{ product.description | strip_html | json }},
“category”: {{ product.type | json }},
“url”: “{{ shop.url }}{{ product.url }}”,
“image”: {
“@type”: “ImageObject”,
“url”: “https:{{ product.featured_image | img_url: ‘1024×1024’ }}”,
“image”: “https:{{ product.featured_image | img_url: ‘1024×1024’ }}”,
“name”: {{ product.featured_image.alt | json }},
“width”: 1024,
“height”: 1024
}
{%- endcapture -%}
{%- elsif template.name == ‘article’ -%}
{%- capture main_entity_microdata -%}
“@type”: “BlogPosting”,
“mainEntityOfPage”: “{{ article.url }}”,
“articleSection”: {{ blog.title | json }},
“keywords”: “{{ article.tags | join: ‘, ‘ }}”,
“headline”: {{ article.title | json }},
“description”: {{ article.excerpt_or_content | strip_html | truncatewords: 25 | json }},
“dateCreated”: “{{ article.created_at | date: ‘%Y-%m-%dT%T’ }}”,
“datePublished”: “{{ article.published_at | date: ‘%Y-%m-%dT%T’ }}”,
“dateModified”: “{{ article.published_at | date: ‘%Y-%m-%dT%T’ }}”,
“image”: {
“@type”: “ImageObject”,
“url”: “https:{{ article.image | img_url: ‘1024×1024’ }}”,
“image”: “https:{{ article.image | img_url: ‘1024×1024’ }}”,
“name”: {{ article.image.alt | json }},
“width”: 1024,
“height”: 1024
},
“author”: {
“@type”: “Person”,
“name”: “{{ article.user.first_name | escape }} {{ article.user.last_name | escape }}”,
“givenName”: {{ article.user.first_name | json }},
“familyName”: {{ article.user.last_name | json }}
},
“publisher”: {
“@type”: “Organization”,
“name”: {{ shop.name | json }},
“logo”: {
“@type”: “ImageObject”,
“url”: “https:{{ ‘logo.png’ | asset_url }}”,
“image”: “https:{{ ‘logo.png’ | asset_url }}”,
“name”: {{ shop.name | json }},
“width”: 100,
“height”: 100
}
},
“commentCount”: {{ article.comments_count }},
“comment”: [
{%- for comment in article.comments limit: 5 -%}
{
“@type”: “Comment”,
“author”: {{ comment.author | json }},
“datePublished”: “{{ comment.created_at | date: ‘%Y-%m-%dT%T’ }}”,
“text”: {{ comment.content | json }}
}{%- unless forloop.last -%},{%- endunless -%}
{%- endfor -%}
]
{%- endcapture -%}
{%- endif -%}

{% if main_entity_microdata != blank %}
<script type=”application/ld+json”>
{
“@context”: “http://schema.org”,
{{ main_entity_microdata }}
}
</script>
{% endif %}

In the theme code editor, add a new snippet, called “microdata-schema.liquid”. Add the code above and save it. Then in your theme.liquid add the following line in side the <head> area (before the <body>:

{% include ‘microdata-schema’ %}

If this helped you, please consider saying thanks and commenting below.

If this didn’t solve it for you, get a Shopify consultant to investigate.

2 thoughts on “Shopify invalid floating point number in property price”

    1. It depends on where your theme has put the microdata. If you are seeing the error, it’s safe to assume it’s there somewhere, so use the Liquify Chrome extension or similar to allow you to search the Shopify theme code properly and search for:

      โ€œpriceโ€: {{ product.price

      If you don’t have microdata in theme at all, I’ve added a section in the main article with a full microdata snippet and instructions on how to add it.

Leave a Comment

Your email address will not be published. Required fields are marked *

Previous post
If you aren't seeing events in GA4 DebugView after pressing…
Scroll to Top