java.math.BigDecimal.shortValue()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(182)

本文整理了Java中java.math.BigDecimal.shortValue()方法的一些代码示例,展示了BigDecimal.shortValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.shortValue()方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:shortValue

BigDecimal.shortValue介绍

[英]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: prestodb/presto

@Override
public short shortValue() { return _value.shortValue(); }

代码示例来源: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: redisson/redisson

@Override
public short shortValue() { return _value.shortValue(); }

代码示例来源:origin: apache/drill

@Override
public short shortValue() { return _value.shortValue(); }

代码示例来源:origin: apache/hive

/** Note - this method will corrupt the value if it doesn't fit. */
@HiveDecimalVersionV1
public short shortValue() {
 return bd.shortValue();
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Returns the value of the specified attribute in the current item as a
 * <code>short</code>.
 *
 * @see #isNull(String) #isNull(String) to check if the attribute value is
 *      null.
 * @see #isPresent(String) #isPresent(String) to check if the attribute
 *      value is present.
 *
 * @throws NumberFormatException
 *             if the attribute value is null or not a valid representation
 *             of a {@code BigDecimal}.
 */
public short getShort(String attrName) {
  BigDecimal bd = getNumber(attrName);
  if (bd == null)
    throw new NumberFormatException
      ("value of " + attrName + " is null");
  return bd.shortValue();
}

代码示例来源:origin: hibernate/hibernate-orm

return (X) Short.valueOf( value.shortValue() );

代码示例来源:origin: org.freemarker/freemarker

/**
 * Converts {@link BigDecimal} to the class given in the {@code formalType} argument if that's a known numerical
 * type, returns the {@link BigDecimal} as is otherwise. Overflow and precision loss are possible, similarly as
 * with casting in Java.
 */
public static Object coerceBigDecimal(BigDecimal bd, Class<?> formalType) {
  // int is expected in most situations, so we check it first
  if (formalType == int.class || formalType == Integer.class) {
    return Integer.valueOf(bd.intValue());
  } else if (formalType == double.class || formalType == Double.class) {
    return Double.valueOf(bd.doubleValue());
  } else if (formalType == long.class || formalType == Long.class) {
    return Long.valueOf(bd.longValue());
  } else if (formalType == float.class || formalType == Float.class) {
    return Float.valueOf(bd.floatValue());
  } else if (formalType == short.class || formalType == Short.class) {
    return Short.valueOf(bd.shortValue());
  } else if (formalType == byte.class || formalType == Byte.class) {
    return Byte.valueOf(bd.byteValue());
  } else if (java.math.BigInteger.class.isAssignableFrom(formalType)) {
    return bd.toBigInteger();
  } else {
    return bd;
  }
}

代码示例来源:origin: aws/aws-sdk-java

dst.put(key, null);
} else if (valueType == Short.class) {
  dst.put(key, (T)Short.valueOf(val.shortValue()));
} else if (valueType == Integer.class) {
  dst.put(key, (T)Integer.valueOf(val.intValue()));

代码示例来源:origin: postgresql/postgresql

case Types.SMALLINT:
case Types.TINYINT:
  return new PGShort( new Short( val.shortValue() ) );
case Types.VARCHAR:
case Types.LONGVARCHAR:

代码示例来源:origin: apache/drill

case VARDECIMAL:
 result = getShortValueOrThrow(
   innerAccessor.getBigDecimal(rowOffset).shortValue(),
   "Java BigDecimal / SQL DECIMAL PRECISION");
 break;

代码示例来源:origin: benas/random-beans

minValue == null ? null : minValue.shortValue(),
    maxValue == null ? null : maxValue.shortValue(),
    random.nextLong()
);

代码示例来源:origin: org.openrdf.sesame/sesame-model

@Override
public short shortValue()
{
  return value.shortValue();
}

代码示例来源:origin: com.jpattern/jporm-api

@Override
public Short wrap(final BigDecimal value) {
  if (value==null) {
    return null;
  }
  return value.shortValue();
}

代码示例来源:origin: jp.dodododo/samurai-dao

@Override
protected Short doGetValue(ResultSet rs, int columnIndex) throws SQLException {
  BigDecimal num = rs.getBigDecimal(columnIndex);
  if (num == null) {
    return null;
  }
  return num.shortValue();
}

代码示例来源:origin: org.zkoss.zk/zul

/** Returns the value in short. If null, zero is returned.
 */
public short shortValue() throws WrongValueException {
  final BigDecimal val = getValue();
  return val != null ? val.shortValue() : 0;
}

代码示例来源:origin: org.apache.hive/hive-storage-api

/** Note - this method will corrupt the value if it doesn't fit. */
@HiveDecimalVersionV1
public short shortValue() {
 return bd.shortValue();
}

代码示例来源:origin: org.apache.openejb.patch/openjpa-jdbc

@Override
public short getShort(ResultSet rs, int column)
  throws SQLException {
  // postgres does not perform automatic conversions, so attempting to
  // get a whole number out of a decimal will throw an exception.
  // fall back to performing manual conversion if the initial get fails
  try {
    return super.getShort(rs, column);
  } catch (SQLException sqle) {
    return super.getBigDecimal(rs, column).shortValue();
  }
}

代码示例来源:origin: org.apache.openjpa/openjpa-jdbc

@Override
public short getShort(ResultSet rs, int column)
  throws SQLException {
  // postgres does not perform automatic conversions, so attempting to
  // get a whole number out of a decimal will throw an exception.
  // fall back to performing manual conversion if the initial get fails
  try {
    return super.getShort(rs, column);
  } catch (SQLException sqle) {
    return super.getBigDecimal(rs, column).shortValue();
  }
}

代码示例来源:origin: jsonzou/jmockdata

@Override
public Short mock(DataConfig mockConfig) {
 /**
  * 若根据正则模拟
  */
 if(mockConfig.numberXeger()!=null){
  return RandomUtils.nextNumberFromXeger(mockConfig.numberXeger()).shortValue();
 }
 return (short) RandomUtils.nextInt(mockConfig.shortRange()[0], mockConfig.shortRange()[1]);
}

相关文章