0

I have tried to split 25.15 into 25 and 15 but it won't work.`

double a=n.nextDouble();
int k=(int)(Math.floor(a));
int g=(int)((Math.floor((a-k)*100)));
user1766169
  • 1,932
  • 3
  • 22
  • 44

3 Answers3

1

I am not sure you want them this way but this should make it:

double doubleValue = n.nextDouble();

int integerPart = (int) doubleValue;
int decimalPart = (int) ((doubleValue - integerPart) * 100);
UDKOX
  • 738
  • 3
  • 15
1

You can do:

 String strNum = Double.toString(25.15); //convert Double to String
 String strInt[] = strNum.split(".");   // split the String and store it in array
 Int num1 = Integer.valueOf(strInt[0]);  // convert it to Integer
 Int num2 = Integer.valueOf(strInt[1]);
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
0

It isn't pretty, but it works.

double a = n.nextDouble();
int part1 = Integer.parseInt(new Double(a).toString().split(".")[0]);
int part2 = Integer.parseInt(new Double(a).toString().split(".")[1]);
secondbreakfast
  • 4,194
  • 5
  • 47
  • 101