Question of the multiplication of fragmented and whole numbers



  • There's a whole number and a shotgun. How to multiply them among themselves to get an exact result. The option with BigDecimal and Math.round() is not considered. There is some other means for such calculations (without transferring numbers to the BigDecimal designer. Without these booths? Is it possible to use outside libraries or other means of language? Example: 24*0.05 = 1.2000000000002 As we see the right answer here is clearly 24*0.05 = 1.2. How do you get 1.2 instead of 1.2000000000002



  • The accuracy of drift-net operations (with a floating point) is guaranteed only to a certain extent. Any library or calculator shall be rounded to some sign. 1. 2,000000000000002, if rounded, it's 1.2. 1.99999999999999999999 to be 2

    Of course, you can put a broken number into a whole, multiplied, then split... but it's not effective. I mean, 1.25 *2 = 125 *2 /100. Better immediately.

    I recommend that the number of signs be selected after comma.

    new BigDecimal(String.valueOf(double)).setScale(yourScale,     BigDecimal.ROUND_HALF_UP);
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2