1

I am having problem with comparing two double numbers up to 3 decimal places. When I try to round 3.1756, I always get 3.176 the last number changes due to 6 last number. Please, help me to get exact number (3.175) from whole decimal numbers.

  • double? Must read good article about floating point. Genrally known is limit of accuracy, but not knowt "representation problem". For strict application use BigDecimal – Jacek Cz Jul 08 '18 at 10:20
  • Make up your mind. Your title says ';decimal numbers' but your question says 'double numbers'. They aren't the same thing. – user207421 Jul 08 '18 at 10:34

1 Answers1

3
 BigDecimal d=new BigDecimal("3.1756").setScale(3,RoundingMode.DOWN);
Debapriya Biswas
  • 1,079
  • 11
  • 23