Skip to content

Commit

Permalink
Zero value should be stored as 0.00 instead of .00
Browse files Browse the repository at this point in the history
Fixes #30
  • Loading branch information
albfernandez committed May 26, 2017
1 parent 10ed2c6 commit 7bfb384
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/linuxense/javadbf/DBFUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,12 @@ public static byte[] doubleFormating(Number num, Charset charset, int fieldLengt
int sizeWholePart = fieldLength - (sizeDecimalPart > 0 ? (sizeDecimalPart + 1) : 0);

StringBuilder format = new StringBuilder(fieldLength);
for (int i = 0; i < sizeWholePart; i++) {
for (int i = 0; i < sizeWholePart-1; i++) {
format.append("#");
}
if (format.length() < sizeWholePart) {
format.append("0");
}
if (sizeDecimalPart > 0) {
format.append(".");
for (int i = 0; i < sizeDecimalPart; i++) {
Expand Down
17 changes: 16 additions & 1 deletion src/test/java/com/linuxense/javadbf/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import org.junit.Assert;
import org.junit.Test;




public class UtilsTest {

private static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1;
Expand Down Expand Up @@ -69,7 +72,19 @@ public void testContains () {
}
@Test
public void doubleFormating() {
// TODO
Assert.assertEquals(
" 0.00",
new String(DBFUtils.doubleFormating(new Double(0.0), Charset.defaultCharset(), 5, 2))
);

Assert.assertEquals(
"10.00",
new String(DBFUtils.doubleFormating(new Double(10.0), Charset.defaultCharset(), 5, 2))
);
Assert.assertEquals(
" 5.05",
new String(DBFUtils.doubleFormating(new Double(5.05), Charset.defaultCharset(), 5, 2))
);
}
@Test
public void testLittleEndian() {
Expand Down

0 comments on commit 7bfb384

Please sign in to comment.