fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.math.BigDecimal ;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15. var a = "0.002000" ;
  16. var b = "0.004000" ;
  17. var expected = "0.000008" ;
  18.  
  19. var actual = new BigDecimal( a ).multiply( new BigDecimal( b ) ) ;
  20. actual = actual.setScale( new BigDecimal( a ).scale() ) ; // Set scale of result to match the scale of inputs.
  21. boolean matching = actual.equals( new BigDecimal( expected ) ) ;
  22.  
  23. System.out.println( "actual: " + actual ) ;
  24. System.out.println( "matching: " + matching ) ;
  25.  
  26. }
  27. }
Success #stdin #stdout 0.12s 36744KB
stdin
Standard input is empty
stdout
actual: 0.000008
matching: true