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개

http://sir.co.kr/qa/
댓글을 작성하시려면 로그인이 필요합니다. 로그인

자유게시판

+
제목 글쓴이 날짜 조회
10년 전 조회 1,224
10년 전 조회 1,375
10년 전 조회 1,248
10년 전 조회 2,485
10년 전 조회 1,195
10년 전 조회 1,192
10년 전 조회 1,709
10년 전 조회 4,177
10년 전 조회 1,189
10년 전 조회 1,933
10년 전 조회 1,134
10년 전 조회 1,391
10년 전 조회 1,173
10년 전 조회 2,193
10년 전 조회 1,811
10년 전 조회 1,398
10년 전 조회 1,417
10년 전 조회 2,784
10년 전 조회 1,132
10년 전 조회 1,320
10년 전 조회 1,816
10년 전 조회 1,802
10년 전 조회 2,016
10년 전 조회 1,222
10년 전 조회 1,329
10년 전 조회 1,241
10년 전 조회 7,581
10년 전 조회 9,924
10년 전 조회 1,717
10년 전 조회 3,001
🐛 버그신고