forked from harrydeluxe/php-liquid
-
Notifications
You must be signed in to change notification settings - Fork 63
Open
Description
Overview
When a math filter returns a float value with no fractional part (e.g., 2.0), PHP Liquid renders it as "2" instead of "2.0". This differs from Ruby Shopify/Liquid, which preserves the decimal notation for float values.
Examples
| Template | Ruby Liquid | PHP Liquid |
|---|---|---|
{{ 1 | plus: 1.0 }} |
2.0 |
2 |
{{ "1" | plus: "1.0" }} |
2.0 |
2 |
{{ 2.0 | times: 1 }} |
2.0 |
2 |
{{ 10 | divided_by: 4.0 }} |
2.5 |
2.5 |
Note: When there is a fractional part (like 2.5), both implementations produce the same output.
Minimal Reproduction
Ruby Liquid
require 'liquid'
template = Liquid::Template.parse('{{ 1 | plus: 1.0 }}')
puts template.render
# => "2.0"PHP Liquid
<?php
require 'vendor/autoload.php';
use Liquid\Template;
$template = new Template();
$template->parse('{{ 1 | plus: 1.0 }}');
echo $template->render();
// => "2"Root Cause
PHP automatically converts float(2.0) to "2" when casting to string:
$f = 2.0;
echo (string)$f; // "2"
$f = 2.5;
echo (string)$f; // "2.5"Refs
- PHP float to string behavior: https://www.php.net/manual/en/language.types.string.php#language.types.string.casting
Metadata
Metadata
Assignees
Labels
No labels