@Test void truncateDecimals() { assertThat(DBDouble.truncateDecimals(3, 4)).isEqualTo("3"); assertThat(DBDouble.truncateDecimals(4.52, 1)).isEqualTo("4.5"); assertThat(DBDouble.truncateDecimals(4.58, 1)).isEqualTo("4.5"); assertThat(DBDouble.truncateDecimals(5.1, 3)).isEqualTo("5.1"); }
static String truncateDecimals(double value, int decimals) { StringBuilder builder = new StringBuilder("0"); if (decimals > 0) builder.append('.'); for (int i = 0; i < decimals; i++) builder.append('#'); DecimalFormat df = new DecimalFormat(builder.toString(), defaultDecimalFormatSymbols); df.setRoundingMode(RoundingMode.FLOOR); return df.format(value); }
DBDouble implements DBType { static String truncateDecimals(double value, int decimals) { StringBuilder builder = new StringBuilder("0"); if (decimals > 0) builder.append('.'); for (int i = 0; i < decimals; i++) builder.append('#'); DecimalFormat df = new DecimalFormat(builder.toString(), defaultDecimalFormatSymbols); df.setRoundingMode(RoundingMode.FLOOR); return df.format(value); } }
DBDouble implements DBType { static String truncateDecimals(double value, int decimals) { StringBuilder builder = new StringBuilder("0"); if (decimals > 0) builder.append('.'); for (int i = 0; i < decimals; i++) builder.append('#'); DecimalFormat df = new DecimalFormat(builder.toString(), defaultDecimalFormatSymbols); df.setRoundingMode(RoundingMode.FLOOR); return df.format(value); } DBDouble();  DBDouble(String typeString); }
DBDouble implements DBType { static String truncateDecimals(double value, int decimals) { StringBuilder builder = new StringBuilder("0"); if (decimals > 0) builder.append('.'); for (int i = 0; i < decimals; i++) builder.append('#'); DecimalFormat df = new DecimalFormat(builder.toString(), defaultDecimalFormatSymbols); df.setRoundingMode(RoundingMode.FLOOR); return df.format(value); } DBDouble();  DBDouble(String typeString); @Override String generateRandom(boolean nullable); @Override String mutate(String currentValue, boolean nullable); @Override boolean hasSeed(Seeds seeds); @Override String generateFromSeed(Seeds seeds); @Override String getTypeString(); @Override String getNormalizedTypeString(); }
DBDouble implements DBType { static String truncateDecimals(double value, int decimals) { StringBuilder builder = new StringBuilder("0"); if (decimals > 0) builder.append('.'); for (int i = 0; i < decimals; i++) builder.append('#'); DecimalFormat df = new DecimalFormat(builder.toString(), defaultDecimalFormatSymbols); df.setRoundingMode(RoundingMode.FLOOR); return df.format(value); } DBDouble();  DBDouble(String typeString); @Override String generateRandom(boolean nullable); @Override String mutate(String currentValue, boolean nullable); @Override boolean hasSeed(Seeds seeds); @Override String generateFromSeed(Seeds seeds); @Override String getTypeString(); @Override String getNormalizedTypeString();  }