本文整理匯總了Java中java.math.BigDecimal.intValueExact方法的典型用法代碼示例。如果您正苦於以下問題:Java BigDecimal.intValueExact方法的具體用法?Java BigDecimal.intValueExact怎麽用?Java BigDecimal.intValueExact使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.math.BigDecimal
的用法示例。
在下文中一共展示了BigDecimal.intValueExact方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateEasterEgg
import java.math.BigDecimal; //導入方法依賴的package包/類
private String generateEasterEgg(Expression expression, BigDecimal result, String query, String stringifiedResult) {
if (result.intValueExact() == 69) {
return stringifiedResult + "\t( ͡° ͜ʖ ͡°)";
}
query = query.replaceAll(" ", "");
if (query.startsWith("2+2-1") && ((expression.isBoolean() && result.intValueExact() == 1) || result.intValueExact() == 3)) {
return stringifiedResult + "\t-\tQuick maths!";
}
if (query.equals("10") && stringifiedResult.equals("10")) {
return "There are only 10 types of people in the world, those who understand binary and those who don't.";
}
return stringifiedResult;
}
示例2: parseInt32
import java.math.BigDecimal; //導入方法依賴的package包/類
/** Parsers an int32 value out of the input. */
static int parseInt32(JsonParser parser) throws IOException {
JsonToken token = parser.currentToken();
if (token == JsonToken.VALUE_NUMBER_INT) {
// Use optimized code path for integral primitives, the normal case.
return parser.getIntValue();
}
// JSON doesn't distinguish between integer values and floating point values so "1" and
// "1.000" are treated as equal in JSON. For this reason we accept floating point values for
// integer fields as well as long as it actually is an integer (i.e., round(value) == value).
try {
BigDecimal value =
new BigDecimal(
parser.getTextCharacters(), parser.getTextOffset(), parser.getTextLength());
return value.intValueExact();
} catch (Exception e) {
throw new InvalidProtocolBufferException("Not an int32 value: " + parser.getText());
}
}