Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85531 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66033 invoked from network); 29 Mar 2015 19:33:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Mar 2015 19:33:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=jakub.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jakub.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.169 as permitted sender) X-PHP-List-Original-Sender: jakub.php@gmail.com X-Host-Fingerprint: 209.85.223.169 mail-ie0-f169.google.com Received: from [209.85.223.169] ([209.85.223.169:36155] helo=mail-ie0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 94/B0-59993-48358155 for ; Sun, 29 Mar 2015 14:33:25 -0500 Received: by iedm5 with SMTP id m5so102753915ied.3 for ; Sun, 29 Mar 2015 12:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=9Bk04JoFLozHbktKsIsGvDUwd+S8tv8ElgzCaBqftwE=; b=tyfoI1h1aNQO6MWpCbqwzoZGJ9NSCc/lK6BjgXapFQXfT+xo5X/rm/W/9FT1a9JERI +JgAMAqYZ7O+CSPzrYErPqm+2Z3kGxuueqtiFAgevvINIARvRqGd4ktvwdoPnpiOBoDN TD2OYvseSrIA+F/e9vV/kRz/4/PBAQbOKzNdJjmwhjWsxAX9bRhBX6FgFWMLi4xK4IEm DHV66Vz/ol4Vgm5LapaR2VLhCMFrMlTXpCTI6GccHXBUTfJPehkyHMP7VMGG1HFlxEz1 kVF+EBNmzUbZX6Hpq+7iSzZrZAHlQ5ic8+IegiUvC2+JwsnpQY7ZnK1vwORI3IVRdHJl 8I/Q== MIME-Version: 1.0 X-Received: by 10.107.17.134 with SMTP id 6mr12763609ior.64.1427657601681; Sun, 29 Mar 2015 12:33:21 -0700 (PDT) Sender: jakub.php@gmail.com Received: by 10.107.39.18 with HTTP; Sun, 29 Mar 2015 12:33:21 -0700 (PDT) Date: Sun, 29 Mar 2015 20:33:21 +0100 X-Google-Sender-Auth: vCfiXiSX4IOqTkRnxdU6IzAQp1I Message-ID: To: PHP internals list Content-Type: multipart/alternative; boundary=001a113f1c58359f2a05127270f2 Subject: JSON float number as string From: bukka@php.net (Jakub Zelenka) --001a113f1c58359f2a05127270f2 Content-Type: text/plain; charset=UTF-8 Hi, I would like to add a new option to JSON for dealing with large floats. The use case is mainly for decoder but can be used for encoder as well. JSON_FLOAT_AS_STRING decode: all float values will be decoded as string - It's often an issue for very large float values with many fractional digits that are coming from platforms that support larger float representation than double. In that case the conversion is lost and there is no way how to get it back (see http://bugs.php.net/68456 [pls ignore my initial dump comments when I didn't get the issue :)] and an example of the lost precision here http://3v4l.org/80iCh ). Converting the value to string keep the precision and resolves the problem. encode: all float values will be encoded as string - re-using the constant for encoder makes sense if PHP creates JSON for platform that support lower float type (e.g. C float) and the precision loss is not acceptable I think that this is more a bugfix as the precision is lost without any way how to get it back (except pre-processing json string with regular expression). I would like to add it to 5.6.x if there are no objections? Cheers Jakub --001a113f1c58359f2a05127270f2--