本文整理了Java中java.math.BigDecimal.shortValueExact()
方法的一些代码示例,展示了BigDecimal.shortValueExact()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.shortValueExact()
方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:shortValueExact
[英]Returns this BigDecimal as a short value if it has no fractional part and if its value fits to the short range ([-215..215-1]). If these conditions are not met, an ArithmeticException is thrown.
[中]如果此BigDecimal没有小数部分并且其值适合短范围([-215..215-1]),则将其作为短值返回。如果不满足这些条件,将抛出算术异常。
代码示例来源:origin: graphql-java/graphql-java
private Short convertImpl(Object input) {
if (input instanceof Short) {
return (Short) input;
} else if (isNumberIsh(input)) {
BigDecimal value;
try {
value = new BigDecimal(input.toString());
} catch (NumberFormatException e) {
return null;
}
try {
return value.shortValueExact();
} catch (ArithmeticException e) {
return null;
}
} else {
return null;
}
}
代码示例来源:origin: com.alibaba/fastjson
public static short shortValue(BigDecimal decimal) {
if (decimal == null) {
return 0;
}
int scale = decimal.scale();
if (scale >= -100 && scale <= 100) {
return decimal.shortValue();
}
return decimal.shortValueExact();
}
代码示例来源:origin: forcedotcom/phoenix
bd = (BigDecimal) value;
try {
bd.shortValueExact();
return true;
} catch (ArithmeticException e) {
代码示例来源:origin: apache/phoenix
@Override
public Short toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
if (l == 0) {
return null;
}
if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE,
PUnsignedTinyint.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE,
PUnsignedInt.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE,
PUnsignedDouble.INSTANCE)) {
return actualType.getCodec().decodeShort(b, o, sortOrder);
} else if (actualType == PDecimal.INSTANCE) {
BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
return bd.shortValueExact();
}
throwConstraintViolationException(actualType,this);
return null;
}
代码示例来源:origin: apache/phoenix
bd = (BigDecimal) value;
try {
bd.shortValueExact();
return true;
} catch (ArithmeticException e) {
代码示例来源:origin: org.beanio/beanio
@Override
protected Short createNumber(BigDecimal bg) throws ArithmeticException {
return bg.shortValueExact();
}
代码示例来源:origin: com.graphql-java/graphql-java
private Short convertImpl(Object input) {
if (input instanceof Short) {
return (Short) input;
} else if (isNumberIsh(input)) {
BigDecimal value;
try {
value = new BigDecimal(input.toString());
} catch (NumberFormatException e) {
return null;
}
try {
return value.shortValueExact();
} catch (ArithmeticException e) {
return null;
}
} else {
return null;
}
}
代码示例来源:origin: org.gradle/gradle-core
@Override
protected void convertNumberToNumber(BigDecimal n, NotationConvertResult<? super Short> result) {
result.converted(n.shortValueExact());
}
}
代码示例来源:origin: asakusafw/asakusafw
@SuppressWarnings("deprecation")
@Override
protected void set(BigDecimal value, ShortOption property) {
property.modify(value.shortValueExact());
}
代码示例来源:origin: org.javamoney.moneta/moneta-core
@Override
public <E extends Number> Short convertExact(Class<E> numberType,
Number number) {
return ConvertBigDecimal.of(number).shortValueExact();
}
代码示例来源:origin: net.sf.ucanaccess/ucanaccess
@FunctionType(functionName = "CINT", argumentTypes = { AccessType.DOUBLE }, returnType = AccessType.INTEGER)
public static Short cint(Double value) throws UcanaccessSQLException {
return new BigDecimal((long) Math.floor(value + 0.499999999999999d)).shortValueExact();
}
代码示例来源:origin: stackoverflow.com
BigDecimal result = BigDecimal.valueOf(328).multiply(
BigDecimal.valueOf(100));
try {
short shortResult = result.shortValueExact();
} catch (ArithmeticException e) {
// overflow
System.out.println("Overflow!");
}
try {
int intResult = result.intValueExact();
} catch (ArithmeticException e) {
// overflow
}
代码示例来源:origin: at.newmedialab.ldpath/ldpath-core-bundle
@Override
public Short transform(RDFBackend<Node> backend, Node node) throws IllegalArgumentException {
if(backend.isLiteral(node)) {
return backend.decimalValue(node).shortValueExact();
} else {
throw new IllegalArgumentException("cannot transform node of type "+
node.getClass().getCanonicalName()+" to short");
}
}
代码示例来源:origin: org.apache.marmotta/ldpath-core
@Override
public Short transform(RDFBackend<Node> backend, Node node, Map<String, String> configuration) throws IllegalArgumentException {
if(backend.isLiteral(node)) {
return backend.decimalValue(node).shortValueExact();
} else {
throw new IllegalArgumentException("cannot transform node of type "+
node.getClass().getCanonicalName()+" to short");
}
}
代码示例来源:origin: apache/marmotta
@Override
public Short transform(RDFBackend<Node> backend, Node node, Map<String, String> configuration) throws IllegalArgumentException {
if(backend.isLiteral(node)) {
return backend.decimalValue(node).shortValueExact();
} else {
throw new IllegalArgumentException("cannot transform node of type "+
node.getClass().getCanonicalName()+" to short");
}
}
代码示例来源:origin: com.aliyun.openservices/ons-client
public static Short castToShort(Object value){
if(value == null){
return null;
}
if(value instanceof BigDecimal){
return ((BigDecimal) value).shortValueExact();
}
if(value instanceof Number){
return ((Number) value).shortValue();
}
if(value instanceof String){
String strVal = (String) value;
if(strVal.length() == 0 //
|| "null".equals(strVal) //
|| "NULL".equals(strVal)){
return null;
}
return Short.parseShort(strVal);
}
throw new JSONException("can not cast to short, value : " + value);
}
代码示例来源:origin: org.beanfabrics/beanfabrics-core
public Short getShort()
throws ConversionException {
if (isEmpty()) {
return null;
} else {
try {
return getBigDecimal().shortValueExact();
} catch (ArithmeticException ex) {
throw new ConversionException(ex);
}
}
}
代码示例来源:origin: org.beanfabrics/beanfabrics-core
public Short getShort()
throws ConversionException {
if (isEmpty()) {
return null;
} else {
try {
return getBigDecimal().shortValueExact();
} catch (ArithmeticException ex) {
throw new ConversionException(ex);
}
}
}
代码示例来源:origin: com.aliyun.phoenix/ali-phoenix-core
@Override
public Short toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
if (l == 0) {
return null;
}
if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE,
PUnsignedTinyint.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE,
PUnsignedInt.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE,
PUnsignedDouble.INSTANCE)) {
return actualType.getCodec().decodeShort(b, o, sortOrder);
} else if (actualType == PDecimal.INSTANCE) {
BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
return bd.shortValueExact();
}
throwConstraintViolationException(actualType,this);
return null;
}
代码示例来源:origin: org.apache.phoenix/phoenix-core
@Override
public Short toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
if (l == 0) {
return null;
}
if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE,
PUnsignedTinyint.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE,
PUnsignedInt.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE,
PUnsignedDouble.INSTANCE)) {
return actualType.getCodec().decodeShort(b, o, sortOrder);
} else if (actualType == PDecimal.INSTANCE) {
BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
return bd.shortValueExact();
}
throwConstraintViolationException(actualType,this);
return null;
}
内容来源于网络,如有侵权,请联系作者删除!