如何将oracle代码转换为java(如何在java中进行除法)



我想把这个[PL/SQL]代码转换成Java代码。

W_LEDGER_BAL := nvl(SUBSTR(W_BAL, 1, 17), 0) / 100;

我试过像这样转换

String amountstr = _ISOResposne.get("48");
String W_LEDGER_BAL = amountstr.substring(0, 17);

其中W_BALamountstr

我不知道怎么除以100。请帮我解决这个错误。

// Get the value.
String amountstr = _ISOResposne.get("48");
if (amountstr == null) {
// If it's null, set it to zero.
amountstr = "0";
}
else {
// otherwise get the first 17 characters.
// (Note that if the length is less than 17, an exception will occur.)
amountstr = amountstr.substring(0, 17);
}
// Convert to a number.
// This will also throw an exception if 'amountstr' cannot be parsed to a number.
java.math.BigDecimal bd = new java.math.BigDecimal(amountstr);
// Divide by one hundred.
bd = bd.divide(new java.math.BigDecimal(100.0d);
// Convert the result to a string.
String W_LEDGER_BAL = bd.toString();

请参阅BigDecimal类的javadoc。

我想您知道Java中的异常是什么。

我还建议您尽量遵守Java命名约定。

最新更新