본문 바로가기

Flutter

[Flutter] 데이터 타입 double 소수점 제거하는 방법

Flutter에서 double의 소수점을 제거하는 방법은 몇 가지가 있습니다. 

아래는 그 중 일부 예시입니다.

 

1. toInt() 메서드 사용

double myDouble = 3.14159;
int myInt = myDouble.toInt();
print(myInt); // 출력: 3

 

2. toString() 및 double.parse() 조합

double myDouble = 3.14159;
String myString = myDouble.toString();
int myInt = double.parse(myString).toInt();
print(myInt); // 출력: 3

 

3. truncate() 메서드 사용

double myDouble = 3.14159;
int myInt = myDouble.truncate();
print(myInt); // 출력: 3

 

4. 소수점 아래 자릿수 제한

double myDouble = 3.14159;
int myInt = (myDouble * 10).toInt();
print(myInt); // 출력: 31