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)));
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)));
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);
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]);
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]);