Image ratio displayed incorrectly (based on locale)


It seems that echo $image->dimensions()->ratio() displays the ratio number formated on locale format, so in french it outputs 1,5 and not 1.5 which is an issue when you want to make calculations or use it in inline styles.

I don’t know if it’s only because of the locale or if smartypants is involved, but I don’t chain it with kt() or any modifiers.


As far as I can see, only the output is shown with a comma. Calculating with the dimensions is no problem:

$ratio = $image->dimensions()->ratio()*2;
echo $ratio;

If you want to echo the number without commas in styles, you can do a string replacement or use PHP’s number_format() method.

If you want to output all numbers with dots instead of commas, you can use detailed locale settings.

It was for css calculations, so I tought had to echo it first but I can do the calculation beforehand. I need to echo it in css after the calculation so I will use number_format. Thank you.

You can do it all in one go if you prefer:

<?= number_format($image->dimensions()->ratio()*2, 2, '.', '') ?>

OK thank you!
(+ some chars for the 20 chars limit :stuck_out_tongue: )