user11065582
user11065582

Reputation:

How to split Double value in dart?

I want to assign two variables to integer and decimal parts on double. how to do it? enter image description here

Upvotes: 1

Views: 4626

Answers (3)

MSARKrish
MSARKrish

Reputation: 4144

final abc = 1.4;
final numberValue = abc.floor();
final floatValue = abc - numberValue;
print(abc);
print(numberValue);
print(floatValue);

Upvotes: 1

Mahadi Hassan Munna
Mahadi Hassan Munna

Reputation: 41

final double abc = 1.4;
int a = int.parse(abc.toString().split(".")[0]);
int b = int.parse(abc.toString().split(".")[1]);

Try this out, it should work fine

Upvotes: 4

Günter Zöchbauer
Günter Zöchbauer

Reputation: 658263

One way would be

int x = abc.toInt()
int y = int.tryParse(abc.toString().split('.')[1]);

Upvotes: 5

Related Questions