I need to extract the decimal part of a float number, but I get weird results:
float n = 22.65f; // I want x = 0.65f, but... x = n % 1; // x = 0.6499996 x
The sound and perfect way to get decimal part of float and double data types, is using with String like this code:
float num=2.35f; String s= new Float(num).toString(); String p=s.substring(s.indexOf('.')+1,s.length()); int decimal=Integer.parseInt(p);