Mantis - Quercus
Viewing Issue Advanced Details
4255 minor have not tried 10-09-10 07:39 10-27-10 05:00
domdorn  
 
normal  
new 4.0.10  
open  
none    
none  
0004255: json_encode(double) not working like in native php
rep by siruslan
http://forum.caucho.com/showthread.php?t=18816 [^]

<?php $arr = array (10.1); echo json_encode($arr); ?>

standart PHP -> [10.1]
quercus PHP -> [10,100000000000]


I found problem in com.caucho.quercus.env.DoubleValue


method toString() contains next code
Code:

String v = String.format("%." + digits + "f", _value);

if change this code to
Code:

      
      DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance();
      dfs.setDecimalSeparator('.');

      DecimalFormat df = new DecimalFormat();
      df.setMaximumFractionDigits(digits);
      df.setDecimalFormatSymbols(dfs);
      String v = df.format(_value);

result will be normal

Notes
(0004801)
mjguisado   
10-27-10 05:00   
I think that isn't a good idea to fix the decimal separator to '.' into the toString method because this method isn't used only by the json_encode method.

Maybe DoubleValue must overwrite the method:
public void jsonEncode(Env env, StringValue sb)

Anyway, the to String method don't apply the locale found in the Env. I think that it has to use the method

static String format(Locale l, String format, Object... args)

instead of

static String format(String format, Object... args)


Best regards