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 | |
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')
-rw-r--r-- | tests/basic/consistent_float_string_casts.phpt | 30 | ||||
-rw-r--r-- | tests/lang/034.phpt | 2 |
2 files changed, 31 insertions, 1 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 diff --git a/tests/lang/034.phpt b/tests/lang/034.phpt index 38ecc0b451..2ed6bce9d7 100644 --- a/tests/lang/034.phpt +++ b/tests/lang/034.phpt @@ -16,4 +16,4 @@ setlocale(LC_NUMERIC, "de_DE.UTF-8", "de_DE", "de", "german", "ge", "de_DE.ISO-8 echo (float)"3.14", "\n"; ?> --EXPECT-- -3,14 +3.14 |