Search code examples
javaandroidmath

How can I show up to 2 decimal places without rounding off?


I want to take two decimal places only for a float without rounding off. eg. 4.21777 should be 4.21 and not 4.22. How do I do this?


Solution

  • A simple answer:

    double x = 4.21777;
    double y = Math.floor(x * 100) / 100;