226227228229230231232233234235236
public void testTruncate() { FixedDecimalNumber fda = new FixedDecimalNumber("1"); try { fda.truncate(9); // too big but not an error } catch (Exception e) { fail(e.getMessage()); } assertEquals("1", fda.get());
234235236237238239240241242243244
} assertEquals("1", fda.get()); fda = new FixedDecimalNumber("1"); try { fda.truncate(-9); fail("should throw exception"); } catch (Exception e) { }
242243244245246247248249250251252
} fda = new FixedDecimalNumber("1.0"); try { fda.truncate(9); // too big but not an error } catch (Exception e) { fail(e.getMessage()); } assertEquals("1.0", fda.get());
250251252253254255256257258259260
} assertEquals("1.0", fda.get()); fda = new FixedDecimalNumber("1.0"); try { fda.truncate(0); } catch (Exception e) { fail(e.getMessage()); } assertEquals("1", fda.get());
258259260261262263264265266267268
} assertEquals("1", fda.get()); fda = new FixedDecimalNumber("1.0"); try { fda.truncate(9); // too big but not an error } catch (Exception e) { fail(e.getMessage()); } assertEquals("1.0", fda.get());
266267268269270271272273274275276
} assertEquals("1.0", fda.get()); fda = new FixedDecimalNumber("1.00000000000000"); try { fda.truncate(0); } catch (Exception e) { fail(e.getMessage()); } assertEquals("1", fda.get());
274275276277278279280281282283284
} assertEquals("1", fda.get()); fda = new FixedDecimalNumber("1.09"); try { fda.truncate(1); } catch (Exception e) { fail(e.getMessage()); } assertEquals("1.0", fda.get());
282283284285286287288289290291292
} assertEquals("1.0", fda.get()); fda = new FixedDecimalNumber("1.09"); try { fda.truncate(2); } catch (Exception e) { fail(e.getMessage()); } assertEquals("1.09", fda.get());