### Question:
DecimalType extends AbstractFieldType implements DefaultValidatorsProvider { @Override public String toString(final Object value, final Locale locale) { if (value == null) { return ""; } if(value instanceof String){ return (String) value; } NumberFormat format = null; if (locale == null) { format = NumberFormat.getNumberInstance(); } else { format = NumberFormat.getNumberInstance(locale); } format.setMaximumFractionDigits(getMaxFractionDigits(value)); return format.format(value); } DecimalType();  DecimalType(final boolean copyable); @Override Class<?> getType(); @Override ValueAndError toObject(final FieldDefinition fieldDefinition, final Object value); @Override String toString(final Object value, final Locale locale); @Override Object fromString(final String value, final Locale locale); @Override Collection<FieldHookDefinition> getMissingValidators(final Iterable<FieldHookDefinition> validators);  }### Answer:
@Test public final void shouldFormatNullAsEmptyString() { String result = decimalType.toString(null, locale); assertEquals("", result); }
@Test public final void shouldFormatDecimalWithoutOfficiousTrimmingFractionalValue() { final String decimalAsString = "1234567." + StringUtils.repeat("9", NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL + 3); BigDecimal value = new BigDecimal(decimalAsString); String result = decimalType.toString(value, locale); assertFormattedEquals(value, result); }
@Test public final void shouldFormatDecimalWithoutOfficiousTrimmingFractionalValue2() { final String decimalAsString = "1234567." + StringUtils.repeat("9", NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL) + "000001"; BigDecimal value = new BigDecimal(decimalAsString); String result = decimalType.toString(value, locale); assertFormattedEquals(value, result); }
@Test public final void shouldFormatDecimalTrimTrailingZeroes() { final String decimalAsString = "1234567." + StringUtils.repeat("9", 3); BigDecimal value = new BigDecimal(decimalAsString + "00000"); String result = decimalType.toString(value, locale); assertFormattedEquals(value, result); }
@Test public final void shouldFormatDecimalTrimTrailingZeroes2() { BigDecimal value = BigDecimal.ZERO.setScale(10); String result = decimalType.toString(value, locale); assertEquals("0", result); }