Bug->Req #80484 [Opn]: json_encode() without converting string to float

From: Date: Fri, 04 Dec 2020 12:31:03 +0000
Subject: Bug->Req #80484 [Opn]: json_encode() without converting string to float
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230840@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80484&edit=1

 ID:                 80484
 Updated by:         cmb@php.net
 Reported by:        teflontelefon at gmail dot com
 Summary:            json_encode() without converting string to float
 Status:             Open
-Type:               Bug
+Type:               Feature/Change Request
-Package:            *General Issues
+Package:            JSON related
 Operating System:   Linux
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

I don't see how this behavior would be a bug.  You explicitly
specified the JSON_NUMERIC_CHECK flag, and the result is valid
JSON.


Previous Comments:
------------------------------------------------------------------------
[2020-12-04 10:25:58] teflontelefon at gmail dot com

Description:
------------
json_encode() with JSON_NUMERIC_CHECK needs a way to encode strings as numbers WITHOUT converting
them to float first. You just can't use money types and pass them with the built in
json_encode() feature. I've looked all over and there is no solution except to create my own
json_encode() which will bear performance issues compared to the built-in method.

Test script:
---------------
echo json_encode(['x'=>'0.00000001'], JSON_NUMERIC_CHECK)."\n";


Expected result:
----------------
{"x":0.00000001}





Actual result:
--------------
{"x":1.0e-8}


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



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


Thread (4 messages)

« previous php.bugs (#230840) next »