diff options
| author | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-02-29 22:47:04 +0100 |
|---|---|---|
| committer | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-05-08 10:52:23 +0200 |
| commit | 4a816584a4d483722485e5163396ea1bb2a6aee7 (patch) | |
| tree | d85d2f5a93b66da2b0b611cdb7600ae2b684ad7c /tests/basic | |
| parent | 6e2cd97b4368e888193819dc0a6d1306b219ec21 (diff) | |
| download | php-git-4a816584a4d483722485e5163396ea1bb2a6aee7.tar.gz | |
Make float to string casts locale-independent
From now on, float to string casting will always behave locale-independently.
RFC: https://wiki.php.net/rfc/locale_independent_float_to_string
Closes GH-5224
Co-authored-by: George Peter Banyard <girgias@php.net>
Diffstat (limited to 'tests/basic')
| -rw-r--r-- | tests/basic/consistent_float_string_casts.phpt | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/basic/consistent_float_string_casts.phpt b/tests/basic/consistent_float_string_casts.phpt new file mode 100644 index 0000000000..adbc1b23ae --- /dev/null +++ b/tests/basic/consistent_float_string_casts.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test that float to string and string to float casts are consistent +--SKIPIF-- +<?php +if (!setlocale( + LC_ALL, + "german", "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8", + "french", "fr", "fr_FR", "fr_FR.ISO8859-1", "fr_FR.ISO_8859-1", "fr_FR.UTF-8", +)) { + die("skip locale needed for this test is not supported on this platform"); +} +?> +--FILE-- +<?php + +setlocale( + LC_ALL, + "german", "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8", + "french", "fr", "fr_FR", "fr_FR.ISO8859-1", "fr_FR.ISO_8859-1", "fr_FR.UTF-8", +); + +$float = 1/3; +$string = (string) $float; +$float = (float) $string; + +printf("%.2f", $float); + +?> +--EXPECT-- +0,33 |
