k

자바 사칙연산 질문

String text = textField.getText();

String text1= textField_1.getText();



double text2 = double.parsedouble(text) +double.parsedouble(text1);
String result = double.toString(text2);
label.setText(result);

double text3 = double.parsedouble(text) - double.parsedouble(text1);
String result1= double.toString(text3);
lblNewLabel.setText(result1);

double text4 = double.parsedouble(text) * double.parsedouble(text1);
String result2= double.toString(text4);
lblNewLabel_1.setText(result2);

Double text5 = Double.parseDouble(text) / Double.parseDouble(text1);
String result3= Double.toString(text5);
lblNewLabel_2.setText(result3);

System.out.println(result3);

 

위처럼 코딩했을땐 사칙연산 계산은 다됩니다.

더블형 을 사용해서 정수인부분도 실수로 나오는데 정수일때는 그냥 정수로 출력하고 실수만 실수로 출력하는 방법좀 알려주세요

도저히 생각이안나요

 

|

댓글 1개

댓글을 작성하시려면 로그인이 필요합니다.

자유게시판

+
제목 글쓴이 날짜 조회
10년 전 조회 1,247
10년 전 조회 1,401
10년 전 조회 1,263
10년 전 조회 2,507
10년 전 조회 1,219
10년 전 조회 1,214
10년 전 조회 1,736
10년 전 조회 4,200
10년 전 조회 1,207
10년 전 조회 1,956
10년 전 조회 1,152
10년 전 조회 1,417
10년 전 조회 1,194
10년 전 조회 2,214
10년 전 조회 1,834
10년 전 조회 1,418
10년 전 조회 1,432
10년 전 조회 2,810
10년 전 조회 1,158
10년 전 조회 1,340
10년 전 조회 1,842
10년 전 조회 1,824
10년 전 조회 2,039
10년 전 조회 1,238
10년 전 조회 1,347
10년 전 조회 1,265
10년 전 조회 7,602
10년 전 조회 9,944
10년 전 조회 1,735
10년 전 조회 3,022