View | Details | Raw Unified | Return to bug 38396
Collapse All | Expand All

(-)C:/D/eclipseworkspaces/Trial/jakarta-poi/src/java/org/apache/poi/hssf/model/FormulaParser.java (-3 / +16 lines)
Lines 231-244 Link Here
231
    
231
    
232
    /** Get a Number */
232
    /** Get a Number */
233
    private String GetNum() {
233
    private String GetNum() {
234
        String Value ="";
234
        StringBuffer value = new StringBuffer();
235
        if  (!IsDigit(look)) Expected("Integer");
235
        if  (!IsDigit(look)) Expected("Integer");
236
        while (IsDigit(look)){
236
        while (IsDigit(look)){
237
            Value = Value + look;
237
            value.append(look);
238
            GetChar();
238
            GetChar();
239
        }
239
        }
240
       
241
        if ('E' == look) {
242
            GetChar();
243
            String Exponent = "";
244
            while (IsDigit(look)) {
245
                Exponent = Exponent + look;
246
                GetChar();
247
            }
248
            int e = Integer.parseInt(Exponent);
249
            for (int i=0; i<e; i++) {
250
                value.append('0');
251
            }
252
        }
240
        SkipWhite();
253
        SkipWhite();
241
        return Value;
254
        return value.toString();
242
    }
255
    }
243
256
244
    /** Output a String with Tab */
257
    /** Output a String with Tab */
(-)C:/D/eclipseworkspaces/Trial/jakarta-poi/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (-1 / +26 lines)
Lines 404-410 Link Here
404
		
404
		
405
	}
405
	}
406
406
407
     public static void main(String [] args) {
407
    // bug 38396 : Formula with exponential numbers not parsed correctly.
408
    public void testExponentialParsing() {
409
        FormulaParser fp = new FormulaParser("13E21/2", null);
410
        fp.parse();
411
        Ptg[] ptgs = fp.getRPNPtg();
412
        assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3);
413
        assertTrue("NumberPtg",(ptgs[0] instanceof NumberPtg));
414
        assertTrue("IntPtg",(ptgs[1] instanceof IntPtg));
415
        assertTrue("DividePtg",(ptgs[2] instanceof DividePtg));
416
    }
417
    public void testExponentialInSheet() {
418
        HSSFWorkbook wb = new HSSFWorkbook();
419
        
420
        wb.createSheet("Cash_Flow");;
421
        
422
        HSSFSheet sheet = wb.createSheet("Test");
423
        HSSFRow row = sheet.createRow(0);
424
        HSSFCell cell;
425
        
426
        cell = row.createCell((short)0);
427
        cell.setCellFormula("13E21/3");
428
        String formula = cell.getCellFormula();
429
        assertEquals("Exponential formula string", "1.3E22/3", formula);
430
    }
431
432
    public static void main(String [] args) {
408
        System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser");
433
        System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser");
409
        junit.textui.TestRunner.run(TestFormulaParser.class);
434
        junit.textui.TestRunner.run(TestFormulaParser.class);
410
    }
435
    }

Return to bug 38396