rfc:json_preserve_fractional_part
This is an old revision of the document!
PHP RFC: JSON Preserve Fractional Part
- Version: 0.1
- Date: 2014-12-25
- Author: Juan Basso, jrbasso@gmail.com
- Status: Draft
- First Published at: http://wiki.php.net/rfc/json_preserve_fractional_part
Introduction
This RFC suggests adding a new option to json_encode function to keep the fractional part on float values.
Proposal
Currently encoding float values like 10.0 to json encodes it as 10, it means that using json_decode function it decodes as integer. The new flag allows the encode to keep the float number encoding 10.0 to 10.0 in JSON.
// Currently var_dump(json_decode(json_encode((float)10))); // Output int(10) // Proposed var_dump(json_decode(json_encode((float)10, JSON_PRESERVE_FRACTIONAL_PART))); // Output double(10)
Backward Incompatible Changes
This RFC introduces no BC breaks.
Proposed PHP Version(s)
The next PHP 5.x.y.
RFC Impact
To SAPIs
No impact.
To Existing Extensions
No impact.
To Opcache
No impact.
New Constants
- JSON_PRESERVE_FRACTIONAL_PART: Preserve the fraction part of float numbers with zero as decimal part.
Future Scope
Define if this behavior should be enabled by default in PHP 7.
Proposed Voting Choices
This RFC requires a 50%+1 majority.
Patches and Tests
Currently implemented on https://github.com/php/php-src/pull/642
Rejected Features
None so far.
rfc/json_preserve_fractional_part.1419529536.txt.gz · Last modified: 2025/04/03 13:08 (external edit)