Skip to content

Math filters return incorrect types compared to Shopify/Liquid #234

@ryo-morimoto

Description

@ryo-morimoto

The math filters (plus, minus, times, modulo) always return float regardless of input types. This differs from Shopify/Liquid's behavior where:

  • Integer + Integer → Integer
  • Float involved → Float
  • String integers (e.g., '20') → treated as Integer
  • String decimals (e.g., '20.0') → treated as Float

Currently, all math filters use (float) cast unconditionally, which breaks compatibility with Shopify/Liquid.

Examples

plus

Template Expected (Shopify) Current (php-liquid)
{{ 1 | plus:1 }} 2 (int) 2.0 (float)
{{ '1' | plus:'1.0' }} 2.0 (float) 2.0 (float) ✓

minus

Template Expected (Shopify) Current (php-liquid)
{{ 5 | minus:1 }} 4 (int) 4.0 (float)
{{ '4.3' | minus:'2' }} 2.3 (float) 2.3 (float) ✓

times

Template Expected (Shopify) Current (php-liquid)
{{ 3 | times:4 }} 12 (int) 12.0 (float)
{{ 'foo' | times:4 }} 0 (int) 0.0 (float)
{{ 0.0725 | times:100 }} 7.25 (float) 7.25 (float) ✓

modulo

Template Expected (Shopify) Current (php-liquid)
{{ 3 | modulo:2 }} 1 (int) 1.0 (float)

Refs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions