Bug 307 - Number Format exception occurs when reading TDP data from EXCEL file
Summary: Number Format exception occurs when reading TDP data from EXCEL file
Status: RESOLVED FIXED
Alias: None
Product: Group17
Classification: Unclassified
Component: Component Controller (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: High critical
Deadline: 2019-11-20
Assignee: chiwmak2-c
URL:
Depends on:
Blocks:
 
Reported: 2019-11-19 20:48 HKT by tssiu5-c
Modified: 2019-11-19 21:28 HKT (History)
0 users

See Also:


Attachments
Screenshot of Number Format exception occurs when reading TDP data from EXCEL file (578.60 KB, image/png)
2019-11-19 20:48 HKT, tssiu5-c
Details

Note You need to log in before you can comment on or make changes to this bug.
Description tssiu5-c 2019-11-19 20:48:55 HKT
Created attachment 26 [details]
Screenshot of Number Format exception occurs when reading TDP data from EXCEL file

Environment:

1: Tool: Eclipse IDE for Java Developers [Version: 2019-06 (4.12.0),Build id: 20190614-1200]
2: OS: Mac OS [Version: 10.15.1, 19B88]

Problem: 

When I output the data retrieved from EXCEL file. 

It shows:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "140.0"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:580)
	at java.lang.Integer.parseInt(Integer.java:615)
	at backend.SpecList.findList(SpecList.java:51)
	at gui.DIYTab$1.actionPerformed(DIYTab.java:72)

After investigation, I found that the developer use "Integer.parseInt()" to convert the TDP data of CPU and VideoCard component from string to Integer. 

Although it shows a integer when open the EXCEL normally, I found the format of the data cell is "Double". Therefore, it is wrong to use Integer.parseInt().

Step to reproduction:
1: Open PCPicker.java in gui package
2: Select price of different component.
3: Click "Calculate" button

I suggest to add exception handler for NumberFormatException, and use Double.parseDouble() to convert the TDP data from String to double.
Comment 1 chiwmak2-c 2019-11-19 21:19:17 HKT
I found the problem you stated. Although the display format in the excel file for CPU and Video card's TDP field are integer, the excel data loading function provided by poi.XSSFSheet will add a decimal point when it changes the integer data to String. Therefore, if we parse the string to a number value for calculation, we need to parse them to double type instead of integer type.
I will follow your suggestion to change the parsing function from Integer.parseint() to Double.parseDouble().
Comment 2 chiwmak2-c 2019-11-19 21:26:00 HKT
The change is applied. Please test again.
Comment 3 tssiu5-c 2019-11-19 21:28:03 HKT
It is glad to hear you reply and solution. Hope it will be fixed shortly. As it really affecting user experience and interrupt normal operation.

(In reply to chiwmak2-c from comment #1)
> I found the problem you stated. Although the display format in the excel
> file for CPU and Video card's TDP field are integer, the excel data loading
> function provided by poi.XSSFSheet will add a decimal point when it changes
> the integer data to String. Therefore, if we parse the string to a number
> value for calculation, we need to parse them to double type instead of
> integer type.
> I will follow your suggestion to change the parsing function from
> Integer.parseint() to Double.parseDouble().