Package org.jExigo

Examples of org.jExigo.FixedDecimalNumber


 
}

public void testPI()
{
   FixedDecimalNumber fda = null;

     try {
    fda = FixedDecimalNumber.makePI(0);
   } catch (Exception e) {
     fail(e.getMessage());
   }

   assertEquals("3", fda.get());

     try {
    fda = FixedDecimalNumber.makePI(1);
   } catch (Exception e) {
     fail(e.getMessage());
   }

   assertEquals("3.1", fda.get());

   try {
    fda = FixedDecimalNumber.makePI(2);
   } catch (Exception e) {
     fail(e.getMessage());
   }

   assertEquals("3.14", fda.get());
  
   try {
      fda = FixedDecimalNumber.makePI(18);
     } catch (Exception e) {
       fail(e.getMessage());
     }

     assertEquals("3.141592653589793238", fda.get());
    
  
}
View Full Code Here


  /**
   * @param args - not used
   */
  public static void main(String[] args) {
   
    FixedDecimalNumber fda = new  FixedDecimalNumber("1.1");
    System.out.print("Adding: " +fda.get());
    FixedDecimalNumber fdb = new FixedDecimalNumber("1.01");
    System.out.print(" + " + fdb.toString() + " = ")// notice get and toString are the same
   
    fda = FixedDecimalArithmetic.add(fda, fdb);
    System.out.println(fda.get());
   
    System.out.print("Subtractring: " +fda.get());
    System.out.print(" - " + fdb.toString() + " = ")// notice get and toString are the same
    fda = FixedDecimalArithmetic.subtract(fda, fdb);
    System.out.println(fda); // notice how precision is not lost
   
    System.out.print("Multiplying: " +fda.get());
    System.out.print(" * " + fdb.toString() + " = ")// notice get and toString are the same
    fda = FixedDecimalArithmetic.multiply(fda, fdb);
    System.out.println(fda); // notice how precision is extended
   
    System.out.print("Dividing: " +fda.get());
    System.out.print(" / " + fdb.toString() + " = ")// notice get and toString are the same
    fda = FixedDecimalArithmetic.divide(fda, fdb);
    System.out.println(fda); // notice how precision is extended
   
    fda.toDecimalPlaces(2);
    System.out.println("truncate to 2 decimal places "+fda);
   
    fda.toDecimalPlaces(3);
    System.out.println("show as 3 decimal places "+fda);
   
    fdb = fda.copy();
   
    System.out.println("fda == fdb is " + (fda.compare(fdb)==0));
   
    fdb.toDecimalPlaces(14);
   
    System.out.println(fda + " == " + fdb + " is " + (fda.compare(fdb)==0));
   
   

View Full Code Here

    }
   
   
public void testSet() {
 
    FixedDecimalNumber fda = new FixedDecimalNumber(".02");
 
  assertEquals("0.02", fda.get());
 
  fda = new FixedDecimalNumber("10.02", 1)// test truncation
 
  assertEquals("10.0", fda.get());
 
  fda =
    new FixedDecimalNumber("10.802", 3);
 
  assertEquals("10.802", fda.get());
 
  fda =
    new FixedDecimalNumber(1002, 3); // test implied decimal
  assertEquals("1.002", fda.get());
 
  fda =
    new FixedDecimalNumber(1002, 2); // test implied decimal
  assertEquals("10.02", fda.get());
 
  fda =
    new FixedDecimalNumber(1002, 0); // test implied decimal
  assertEquals("1002", fda.get());
 
}
View Full Code Here

}

public void  testAdd()
{
 
  FixedDecimalNumber fda =
    new FixedDecimalNumber("10.02");
 
  FixedDecimalNumber  fdb =   new FixedDecimalNumber("10.02");
  fdb = FixedDecimalArithmetic.add(fda, fdb);//10.02+10.02
  assertEquals("20.04", fdb.get());
 
  fdb = new FixedDecimalNumber("-10.02");//10.02+(-10.02)
  fdb = FixedDecimalArithmetic.add(fda, fdb);
  assertEquals("0.00", fdb.get());
 
 
  fdb = new FixedDecimalNumber("10.821", 3);
  fdb = FixedDecimalArithmetic.add(fda, fdb); //10.02+10.821
  assertEquals("20.841", fdb.get());
 
  fdb = new FixedDecimalNumber("20010.821", 13);
  fdb = FixedDecimalArithmetic.add(fda, fdb); //10.02+20010.821 to 13 places
  assertEquals("20020.8410000000000", fdb.get());
 
   
}
View Full Code Here

   
}
public void testSubtract()
{
 
  FixedDecimalNumber fda = new FixedDecimalNumber(".02");
  FixedDecimalNumber fdb = new FixedDecimalNumber("10.02");
  fdb = FixedDecimalArithmetic.subtract(fda, fdb); // .02-10.02
  assertEquals("-10.00", fdb.get());
 
 
  fdb =new FixedDecimalNumber("10.821", 3);
  fdb = FixedDecimalArithmetic.subtract(fda, fdb);//.02-10.821
  assertEquals("-10.801", fdb.get());

  fdb = new FixedDecimalNumber("-.02");
  fdb = FixedDecimalArithmetic.subtract(fda, fdb); //.02-(-.02)
  assertEquals("0.04", fdb.get());

 
  fdb = new FixedDecimalNumber("20010.821", 13);
  fdb = FixedDecimalArithmetic.subtract(fda, fdb); //.02-20020.821
  assertEquals("-20010.8010000000000", fdb.get());
 
  fdb = new FixedDecimalNumber("-20010.819", 4);
  fda = new FixedDecimalNumber("10.020");
  fdb = FixedDecimalArithmetic.subtract(fda, fdb);//10.020-(-20010.819)
  assertEquals("20020.8390", fdb.get());
 
}
View Full Code Here

  assertEquals("20020.8390", fdb.get());
 
}
public void testMultiply() {
 
    FixedDecimalNumber fda = new FixedDecimalNumber(".02");
    FixedDecimalNumber fdb = new FixedDecimalNumber("10.02");
  fdb = FixedDecimalArithmetic.multiply(fda, fdb); //.02*10.02
  assertEquals("0.2004", fdb.get());
 
  fdb = new FixedDecimalNumber("-.02");
  fdb = FixedDecimalArithmetic.multiply(fda, fdb); //.02*(-.02)
  assertEquals("-0.0004", fdb.get());

 
  fdb = new FixedDecimalNumber("10.821", 3);
  fdb = FixedDecimalArithmetic.multiply(fda, fdb);//.02*10.821
  assertEquals("0.21642", fdb.get());
 
  fdb = new FixedDecimalNumber("20010.821", 13);
  fdb = FixedDecimalArithmetic.multiply(fda, fdb);//.02*20010.821 to 13 places
  assertEquals("400.216420000000000", fdb.get());
 
  fdb = new FixedDecimalNumber("-20010.821", 4); //.02*-20010.821
  fdb = FixedDecimalArithmetic.multiply(fda, fdb); //.02*-20010.821
  assertEquals("-400.216420", fdb.get());
 
 
 
}
View Full Code Here

 
}
public void testDivide()
{
 
    FixedDecimalNumber fda = new FixedDecimalNumber(".02");
    FixedDecimalNumber fdb = new FixedDecimalNumber("2");
  fdb = FixedDecimalArithmetic.divide(fda, fdb); // .02/2
  assertEquals("0.01", fdb.get());

  fdb = new FixedDecimalNumber("-.02");
  fdb = FixedDecimalArithmetic.divide(fda, fdb); // .02/.02
  assertEquals("-1.00", fdb.get());


  fdb =
    new FixedDecimalNumber("66", 3);
  fdb = FixedDecimalArithmetic.divide(fda, fdb); // .02/.066
  assertEquals("0.00", fdb.get());
 
  fda = new FixedDecimalNumber(".005");
  fdb = new FixedDecimalNumber(".05");
  fdb = FixedDecimalArithmetic.divide(fda, fdb); //.005/.05
  assertEquals("0.100", fdb.get());
 
  fdb = new FixedDecimalNumber("50");
  fdb = FixedDecimalArithmetic.divide(fda, fdb); // .005/50
  assertEquals("0.000", fdb.get());
 
 
  fda = new FixedDecimalNumber("500");// don't expect decimal point character
  fdb = new FixedDecimalNumber("50");
  fdb = FixedDecimalArithmetic.divide(fda, fdb); //  500/50
  assertEquals("10", fdb.get());
 
  fdb = new FixedDecimalNumber("0.50");
  fda = new FixedDecimalNumber("500.")// expect decimal point character
  fdb = FixedDecimalArithmetic.divide(fda, fdb)//   500/.50
  assertEquals("1000", fdb.get());
 

}
View Full Code Here

}

public void testCompare()
{
    FixedDecimalNumber fda = new FixedDecimalNumber(".02");
    FixedDecimalNumber fdb = new FixedDecimalNumber("10.02");
   
    assertTrue(fda.compare(fdb)<0);
   
    fdb = new FixedDecimalNumber("-10.02");
   
    assertTrue(fda.compare(fdb)>0);
   
    fdb = new FixedDecimalNumber(".02000000000");
   
    assertTrue(fda.compare(fdb)==0);
 
    fdb = new FixedDecimalNumber("-10.020000000");
   
    assertTrue(fda.compare(fdb)>0);
   
    fdb = FixedDecimalArithmetic.multiply(fdb, new FixedDecimalNumber("-1.0"));
   
    assertTrue(fda.compare(fdb)<0);

 
}
View Full Code Here

 
}

public void testChangeDecimalPosition()
{
  FixedDecimalNumber fda = new FixedDecimalNumber(".02");
    assertEquals(fda.get(), "0.02");
   
    fda.toDecimalPlaces(3);
    assertEquals(fda.get(), "0.020");
    assertNotSame(fda.get(), "0.02");
}
View Full Code Here

}


public void testCopy()
{
    FixedDecimalNumber fda = new FixedDecimalNumber(".02");
    FixedDecimalNumber fdb = new FixedDecimalNumber("10.02");
   
    assertTrue(fda.compare(fdb)!=0);
    assertNotSame(fda.get(), fdb.get());
    fdb = fda.copy();
   
    assertEquals(fda.get(), fdb.get());
    assertTrue(fda.compare(fdb)==0);
}
View Full Code Here

TOP

Related Classes of org.jExigo.FixedDecimalNumber

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.