Skip to content

Commit

Permalink
toBruch() implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
oboehm committed Apr 2, 2018
1 parent 67d74b0 commit 1d01565
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/de/jfachwert/math/PackedDecimal.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ public boolean isBruch() {
return toString().contains("/");
}

/**
* Liefert die Zahl als Bruch zurueck.
*
* @return Bruch als Zahl
*/
public Bruch toBruch() {
return Bruch.of(toString());
}

/**
* Liefert die gepackte Dezimalzahl wieder als {@link BigDecimal} zurueck.
*
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/de/jfachwert/math/PackedDecimalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ public void testIsBruch() {
assertTrue(PackedDecimal.valueOf("1/2").isBruch());
}

/**
* Testmethode fuer {@link PackedDecimal#toBruch()}.
*/
@Test
public void testToBruch() {
assertEquals(Bruch.of("1/2"), PackedDecimal.valueOf("1/2").toBruch());
}

/**
* Testmethode fuer {@link PackedDecimal#toBigDecimal()}.
*/
Expand Down

0 comments on commit 1d01565

Please sign in to comment.