Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dumping floats in "comma locales" results in a string value #74

Open
lukasbestle opened this issue Feb 19, 2019 · 0 comments
Open

Dumping floats in "comma locales" results in a string value #74

lukasbestle opened this issue Feb 19, 2019 · 0 comments

Comments

@lukasbestle
Copy link

We use Spyc for Kirby CMS and have stumbled upon an issue that only occurs if PHP's number locale is set to a locale that uses commas as a decimal separator (like German for example).

Consider the following simple test case:

<?php

require_once 'Spyc.php';

$data = ['key' => 1.23];

// basic example
$yaml = Spyc::YAMLDump($data, false, false, true);
echo $yaml; // key: 1.23

// switch to a different locale that uses
// comma as decimal separator
setlocale(LC_NUMERIC, 'de_DE');

// Spyc now uses that for the YAML output as well,
// even though it shouldn't
$yaml = Spyc::YAMLDump($data, false, false, true);
echo $yaml; // key: '1,23'

As you can see, the output of Spyc differs even though the input value (a simple float) is the same.

We made a temporary fix in Kirby, maybe that's of use to you or maybe there's a better solution for this all-together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant