Fail Data With Excel (Float)

EduBw :

I generated Excel with Data from BD, All is correct a except the type float.

In my BD I have "3.2" but in my Excell I have -> 3,20000004768372

    try {

        XSSFSheet sheet = workbook.createSheet(eyelash);
        XSSFDataFormat format = workbook.createDataFormat();
        style.setDataFormat(format.getFormat("Text")); //I need type text for others inputs in my Excel
        styleRow.setDataFormat(format.getFormat("Text"));
        String[] header = {"width"};
        XSSFRow rowhead = sheet.createRow((short) 0);
        XSSFCell cell;

            int myRowData = 1;
            XSSFRow row = sheet.createRow((short) myRowData);

            List<MyClass> list = this.select();

            for (int i = 0; i < list.size(); i++) {

                row.createCell(0).setCellValue(list.get(i).getWidth()); 
                myRowData++;
                row = sheet.createRow((short) myRowData);

        }

    } catch (Exception ex) {}

CLASS JAVA->

public class MyClass{

 private float width;

 public MyClass(){}

 public MyClass(float width){
   width=width;
 }

public void setWidth(float width) {
    this.width= width;
}


public Float getWidth() {
    return width;
} 

}

I can't use round because else never know width real.

Sanguine :

If the precision of the values is a problem you should look at the difference between floats and doubles, as seen here and here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=108603&siteId=1