자바 숫자 를 문자 로 - jaba susja leul munja lo

숫자를 문자로 변환하는 방법 toString


숫자를 문자로 변환하기 위해서는 toString 함수를 사용해야 합니다.

toString 함수는 각 객체 클래스의 함수입니다.

문자열로 바꾸기 위해선 타입별에 따른 객체를 사용해 주어야 합니다.

용도 함수
정수(Int) Integer.toString
실수(Float) Float.toString
실수(Double) Double.toString
롱(Long) Long.toString

예제 코드

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

public class convertIntString {

public static void main(String[] args) {

// TODO Auto-generated method stub

int from_num = 100;

String to_st;

to_st = Integer.toString(from_num);

System.out.println("Int to String : " + to_st);

float from_float = (float10.03;

Float.toString(from_float);

double from_double = (double10.03;

Double.toString(from_double);

long from_long = (long10.03;

Long.toString(from_long);

}

}    

cs

자바 숫자 를 문자 로 - jaba susja leul munja lo

문자를 숫자로 변환하는 방법 parse


문자를 숫자로 변환하기 위해서는 parse 함수를 사용해야 합니다.

parse 함수는 각 객체의 클래스의 함수입니다.

숫자로 바꾸기 위해선 타입별에 따른 객체와 함수를 사용해 주어야 합니다.

용도 함수
정수(Int) Integer.parseInt
실수(Float) Float.parseFloat
실수(Double) Double.parseDouble
롱(Long) Long.parseLong

예제 코드

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

public class convertIntString {

public static void main(String[] args) {

// TODO Auto-generated method stub

String from_st = "200";

int to_num;

to_num = Integer.parseInt(from_st);

System.out.println("String to Int : " + to_num);

float to_float;

double to_double;

long to_long;

to_float = Float.parseFloat(from_st);

to_double = Double.parseDouble(from_st);

to_long = Long.parseLong(from_st);

}

}    

cs

자바 숫자 를 문자 로 - jaba susja leul munja lo

자바 문자를 숫자로 변환하는 방법 parse

자바 숫자를 문자로 변환하는 방법 toString