How to prevent Gson from converting a long number (a json string ) to scientific notation format?

前端 未结 7 2176
予麋鹿
予麋鹿 2020-11-29 06:14

I need to convert json string to java object and display it as a long. The json string is a fixed array of long numbers:

{numbers
[ 268627104, 485677888, 506         


        
7条回答
  •  鱼传尺愫
    2020-11-29 06:27

    I did not find a solution to my problem of gson formatting numbers ending in 0 to scientific notation. I instead used a work-around to convert this scientific notation into a double that I formatted with commas. "value" is the json string.

      private String formatNumber(String value) { 
        double dValue = Double.parseDouble(value);
        String pattern = "#,###";
        DecimalFormat formatter = new DecimalFormat(pattern);
        String newNumber = formatter.format(dValue);
    
                return newNumber;
    }
    

    This doesn't answer the question asked but is an added step to work-around the problem to display the numbers as required by the system.

提交回复
热议问题