private static String dblString(BigDecimal decimalValue,int precision,int availableSpace){
  BigDecimal decimal=decimalValue;
  if (precision >= 0) {
    decimal=decimalValue.setScale(precision,RoundingMode.HALF_UP);
  }
  double absInput=Math.abs(decimalValue.doubleValue());
  if (absInput > 0d && absInput < MAX_DECIMAL_VALUE_TO_USE_PLAIN_STRING) {
    String value=decimal.toPlainString();
    if (value.length() < availableSpace) {
      return value;
    }
  }
  String value=decimalValue.toString();
  while (value.length() > availableSpace) {
    decimal=decimalValue.setScale(decimal.scale() - 1,BigDecimal.ROUND_HALF_UP);
    value=decimal.toString();
  }
  return value;
}

private static String dblString ( BigDecimal decimalValue , int precision , int availableSpace ) { BigDecimal decimal = decimalValue ; if ( precision >= 0 ) { decimal = decimalValue . setScale ( precision , RoundingMode . HALF_UP ) ; } double absInput = Math . abs ( decimalValue . doubleValue ( ) ) ; if ( absInput > 0d && absInput < MAX_DECIMAL_VALUE_TO_USE_PLAIN_STRING ) { String value = decimal . toPlainString ( ) ; if ( value . length ( ) < availableSpace ) { return value ; } } String value = decimalValue . toString ( ) ; while ( value . length ( ) > availableSpace ) { decimal = decimalValue . setScale ( decimal . scale ( ) - 1 , BigDecimal . ROUND_HALF_UP ) ; value = decimal . toString ( ) ; } return value ; }
create a string from a bigdecimal making sure that it ' s not longer than the available space .
