rfc:json_preserve_fractional_part
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:json_preserve_fractional_part [2014/12/25 18:58] – jrbasso | rfc:json_preserve_fractional_part [2015/01/18 04:30] – jrbasso | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: JSON Preserve Fractional Part ====== | + | ====== PHP RFC: Preserve Fractional Part in JSON encode |
- | * Version: | + | * Version: |
* Date: 2014-12-25 | * Date: 2014-12-25 | ||
* Author: Juan Basso, jrbasso@gmail.com | * Author: Juan Basso, jrbasso@gmail.com | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 18: | Line 18: | ||
Testing the same behavior in other languages it shows that Go and JavaScript encode 10.0 to 10, but Python, C (lib jansson) and Ruby encode it to 10.0. | Testing the same behavior in other languages it shows that Go and JavaScript encode 10.0 to 10, but Python, C (lib jansson) and Ruby encode it to 10.0. | ||
- | The goal of this RFC is propose a new json_encode option called | + | The goal of this RFC is propose a new json_encode option called |
<PHP> | <PHP> | ||
// Currently | // Currently | ||
+ | echo json_encode(10.0); | ||
+ | echo json_encode(10.1); | ||
var_dump(json_decode(json_encode(10.0))); | var_dump(json_decode(json_encode(10.0))); | ||
var_dump(10.0 === json_decode(json_encode(10.0))); | var_dump(10.0 === json_decode(json_encode(10.0))); | ||
// Proposed | // Proposed | ||
- | var_dump(json_decode(json_encode(10.0, | + | echo json_encode(10.0); |
- | var_dump(10.0 === json_decode(json_encode(10.0, | + | echo json_encode(10.1); |
+ | echo json_encode(10.0, | ||
+ | echo json_encode(10.1, | ||
+ | var_dump(json_decode(json_encode(10.0, | ||
+ | var_dump(10.0 === json_decode(json_encode(10.0, | ||
</ | </ | ||
Line 66: | Line 72: | ||
==== New Constants ==== | ==== New Constants ==== | ||
- | - JSON_PRESERVE_FRACTIONAL_PART: Preserve the fraction part of float numbers with zero as decimal part. | + | - JSON_PRESERVE_ZERO_FRACTION: Preserve the fraction part of float numbers with zero as decimal part. |
==== Performance ==== | ==== Performance ==== | ||
Line 73: | Line 79: | ||
The table below shows the performance of the code below (PS: not using the new flag): | The table below shows the performance of the code below (PS: not using the new flag): | ||
<PHP> | <PHP> | ||
- | $data = array_fill(0, | + | $number = 1.0; // Or 1.1 |
+ | $data = array_fill(0, | ||
$iterations = 10000; | $iterations = 10000; | ||
Line 101: | Line 108: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
This RFC requires a 50%+1 majority. | This RFC requires a 50%+1 majority. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | * Voting opened: 2015-01-11 02:55 UTC | ||
+ | * Voting closes: 2015-01-18 02:55 UTC | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== |
rfc/json_preserve_fractional_part.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1