我正在尝试将 6.75 的销售税率与我的字符串格式的预期值 6.75 进行比较。我编写了下面的 Groovy 代码行来实现这一点,但是我得到了数字格式异常,我无法弄清楚问题出在哪里
Groovy 代码
def jsonSlurper = new JsonSlurper()
def parsedResponseJson=jsonSlurper.parseText(context.expand('${StandardFinance#Response}'))
def actualSalesTaxRate = parsedResponseJson.CustomerQuoteFinanceResponse.StandardFinanceResponse.Responses[0].StandardPaymentEngineFinanceResponse.paymentWithTaxes.financeItemizedTaxes.salesTax.taxParameters.rate
def actualSalesTaxRate = parsedResponseJson.CustomerQuoteFinanceResponse.StandardFinanceResponse.Responses[0].StandardPaymentEngineFinanceResponse.paymentWithTaxes.financeItemizedTaxes.salesTax.taxParameters.rate
log.info actualSalesTaxRate.size()
actualSalesTaxRate = Float.parseFloat(actualSalesTaxRate)
def expectedSalesTaxRate = "6.75"
log.info expectedSalesTaxRate.size()
expectedSalesTaxRate = Float.parseFloat(expectedSalesTaxRate)
assert expectedSalesTaxRate.toString() == actualSalesTaxRate.toString(),"FAIL --- Sales Tax Rate is different"
JSON 响应
{
"CustomerQuoteFinanceResponse": {
"StandardFinanceResponse": {
"Responses": [{
"StandardPaymentEngineFinanceResponse": {
"class": ".APRNonCashCustomerQuote",
"RequestID": "1",
"term": "48",
"financeSourceId": "F000CE",
"paymentWithTaxes": {
"class": ".FinancePaymentWithTaxes",
"amountFinanced": "34523.48",
"monthlyPayment": "782.60",
"monthlyPaymentWithoutDealerAddOns": 782.6,
"financeItemizedTaxes": {
"salesTax": {
"taxParameters": {
"rate": "6.75"
},
"salesTaxAmount": "2322.61"
}
}
}
}
}]
}
}
}