From ce8fe5c99b22a6f39c67795bb8fb444585774134 Mon Sep 17 00:00:00 2001 From: Maxim Kuleshov Date: Thu, 21 Mar 2024 15:54:50 +0300 Subject: [PATCH] Parse number as floating-point if it doesn't fit in integer; try hard to use integer when possible though --- jzon.inc.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/jzon.inc.php b/jzon.inc.php index 081aba7..d9e493b 100644 --- a/jzon.inc.php +++ b/jzon.inc.php @@ -293,10 +293,16 @@ class jzonParser } $str_num = substr($this->in, $start, $this->c - $start); + + $fval = floatval($str_num); + $ival = intval($str_num); + if($is_float) - $out = floatval($str_num); + $out = $fval; + else if(($ival < PHP_INT_MAX && $ival > PHP_INT_MIN) || strval($ival) === $str_num) + $out = $ival; else - $out = intval($str_num); + $out = $fval; } private function parse_true(&$out)