harrydeluxe / php-liquid

A PHP port of Ruby's Liquid Templates
http://www.delacap.com/artikel/Liquid-Templates/
MIT License
239 stars 119 forks source link

Math filters always return whole integers #28

Closed schmoove closed 7 years ago

schmoove commented 9 years ago

So if you do:

{{ 1 | plus: 1.5 }}

You will get 2

I would recommend the (int) type castings for values returned by the Math Filters be changed to (float) to avoid this.

I'm pretty sure it's not the behaviour of the original Liquid implementation.

schmoove commented 8 years ago

This is also occurring for {% assign %}, which is really frustrating if you are doing any cumulative totals with Liquid.

Can be fixed by modifying LiquidContext.class.php like so:

public function set($key, $value, $global = false)
    {
        if ( is_numeric($value) )
        {
            if ( is_float($value) )
            {
                $value = (float) $value;
            }
            else
            {
                $value = (int) $value;          
            }
        }

        if ( $global )
        ...
schmoove commented 7 years ago

Resolved by #30