文字提取:(可能字母会有错)
def formatNumber(double number, int decimalPlaces) [String format ="%." + decimalPlaces + "fString formattedNumber = String.format(format. numberformattedNumber = formattedNumber.replaceAll(" 1.?0+$",)
return formattedNumber
//示例用法
def number1 = 1.87400def result1 = formatNumber(number1, 3)
println(result1) //输出: 1.874
def number2 = 43943.273230
def result2 = formatNumber(number2. 6println(result2) // 输出: 43943.27323
def formatNumber(double number, int decimalPlaces) [String format ="%." + decimalPlaces + "fString formattedNumber = String.format(format. numberformattedNumber = formattedNumber.replaceAll(" 1.?0+$",)
return formattedNumber
//示例用法
def number1 = 1.87400def result1 = formatNumber(number1, 3)
println(result1) //输出: 1.874
def number2 = 43943.273230
def result2 = formatNumber(number2. 6println(result2) // 输出: 43943.27323