Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0004255 [Quercus] minor have not tried 10-09-10 07:39 10-27-10 05:00
Reporter domdorn View Status public  
Assigned To
Priority normal Resolution open  
Status new   Product Version 4.0.10
Summary 0004255: json_encode(double) not working like in native php
Description 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]


Additional Information 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
Attached Files

- Relationships

- 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
 

- Issue History
Date Modified Username Field Change
10-09-10 07:39 domdorn New Issue
10-27-10 05:00 mjguisado Note Added: 0004801
10-27-10 09:23 kdecherf Issue Monitored: kdecherf
01-30-11 10:03 kdecherf Issue End Monitor: kdecherf


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
32 total queries executed.
27 unique queries executed.
Powered by Mantis Bugtracker