本文整理汇总了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());
}
}