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
If you just want to print the number to 2dp you can use DecimalFormat.
DecimalFormat df= new DecimalFormat("#.##"); System.out.println(df.format(f));
If you want fixed point numbers internally use BigDecimal