Closed
Description
Symfony version(s) affected
6.0.6
Description
When I dd(12.5)
, for instance, it is presented like float 12.5,0
.
How to reproduce
dd(12.5)
Possible Solution
I can't help with a definitive solution, but I research where the problem is started, and is basically from AbstractDumper
constructor, that depends on localeconv()
information. The float to string conversion occur in CliDumper::dumpScalar()
.
For me, it returns:
array (size=18)
'decimal_point' => string ',' (length=1)
...
The float dumper is something like:
case 'double':
$style = 'num';
if (isset($this->styles['float'])) {
$style = 'float';
}
switch (true) {
case \INF === $value: $value = 'INF'; break;
case -\INF === $value: $value = '-INF'; break;
case is_nan($value): $value = 'NAN'; break;
default:
$value = (string) $value;
if (!str_contains($value, $this->decimalPoint)) {
$value .= $this->decimalPoint.'0';
}
break;
}
break;
But (string) $value
returns string '12.5'
, that is incompatible to localeconv()
info.
My suggestion is detect separator based on a float info directly. For instance:
$this->decimalPoint = str_replace('1', '', (string) 1.1); // => "."
Additional Context
No response