def formatDecimalPrecision(def dataValue, int decimalPrecision){
def regEx_Numeric = '-?[1-9]\d*$|-?([1-9]\d*\.\d*|0\.\d*|0?\.0+|0)$' NumberFormat format = NumberFormat.getNumberInstance() format.setMaximumFractionDigits(decimalPrecision) dataValue = dataValue.toString() if(dataValue.isBigDecimal()){ dataValue = new BigDecimal(dataValue).toPlainString() } if(dataValue.matches(regEx_Numeric)){ //Switch String to double firstly dataValue = Double.parseDouble(dataValue) dataValue = format.format(dataValue) dataValue = format.parse(dataValue).toString() } return dataValue }