skip to Main Content

I’m trying to calculate growth rate between two months and I’m getting round numbers instead of floating. Is there a way to prevent liquid from rounding numbers?

{{ articles_created_this_month_count | minus: articles_created_last_month_count | divided_by: articles_created_last_month_count | times: 100 }}%

{{ articles_created_this_month_count | minus: articles_created_last_month_count | divided_by: articles_created_last_month_count | times: 100 }}%

2

Answers


  1. use javascript for pet projects like this where Liquid is not appropriate

    Login or Signup to reply.
  2. As with many programming languages, when Liquid divides an integer with an integer, the result will always be an integer again. So 5 / 2 will equal 2. But 5.0 / 2 will be 2.5. So you could multiple your articles_created_this_month_count with 1.0:

    {{ articles_created_this_month_count | times: 1.0 | minus: articles_created_last_month_count | divided_by: articles_created_last_month_count | times: 100 }}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search