Bug #69255 [Opn->Nab]: Double to Int convertation while json encode-decode

From: Date: Wed, 18 Mar 2015 21:21:34 +0000
Subject: Bug #69255 [Opn->Nab]: Double to Int convertation while json encode-decode
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191455@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69255&edit=1

 ID:                 69255
 Updated by:         cmb@php.net
 Reported by:        oleksiy dot tykhonovskyy at agito dot pl
 Summary:            Double to Int convertation while json encode-decode
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            JSON related
 PHP Version:        5.5.22
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

The JSON specifications don't distinguish between integer and
floating point numbers (or other representations), therefore 11.0
and 11 are considered identical, so json_encode() chooses the
shortest representation.

However, there will be a new option to json_encode(), 
JSON_PRESERVE_ZERO_FRACTION, in PHP 7[1].

[1] <https://wiki.php.net/rfc/json_preserve_fractional_part>


Previous Comments:
------------------------------------------------------------------------
[2015-03-18 09:57:29] oleksiy dot tykhonovskyy at agito dot pl

Description:
------------
Double to Int convertation while json encode-decode in case number has .0 end... 

---
From manual page: http://www.php.net/function.json-encode
---


Test script:
---------------
php > $a = ['price' => 11.00];
php > var_dump($a);
array(1) {
  'price' =>
  double(11)
}
php > var_dump(json_decode(json_encode($a), true));
array(1) {
  'price' =>
  int(11)
}



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69255&edit=1


Thread (2 messages)

« previous php.bugs (#191455) next »