本文整理了Java中java.math.BigDecimal.byteValue()
方法的一些代码示例,展示了BigDecimal.byteValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.byteValue()
方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:byteValue
[英]Returns this BigDecimal as a byte value if it has no fractional part and if its value fits to the byte range ([-128..127]). If these conditions are not met, an ArithmeticException is thrown.
[中]如果此BigDecimal没有小数部分并且其值适合字节范围([-128..127]),则将其作为字节值返回。如果不满足这些条件,将抛出算术异常。
代码示例来源:origin: com.alibaba/fastjson
public static byte byteValue(BigDecimal decimal) {
if (decimal == null) {
return 0;
}
int scale = decimal.scale();
if (scale >= -100 && scale <= 100) {
return decimal.byteValue();
}
return decimal.byteValueExact();
}
代码示例来源:origin: apache/hive
@HiveDecimalVersionV1
public byte byteValue() {
return bd.byteValue();
}
代码示例来源:origin: hibernate/hibernate-orm
return (X) Byte.valueOf( value.byteValue() );
代码示例来源: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: apache/drill
case VARDECIMAL:
result = getByteValueOrThrow(
innerAccessor.getBigDecimal(rowOffset).byteValue(),
"Java BigDecimal / SQL DECIMAL PRECISION");
break;
代码示例来源:origin: benas/random-beans
minValue == null ? null : minValue.byteValue(),
maxValue == null ? null : maxValue.byteValue(),
random.nextLong()
);
代码示例来源:origin: org.openrdf.sesame/sesame-model
@Override
public byte byteValue()
{
return value.byteValue();
}
代码示例来源:origin: it.tidalwave.bluebill/it-tidalwave-android-org-openrdf-sesame-model
@Override
public byte byteValue()
{
return value.byteValue();
}
代码示例来源:origin: jp.dodododo/samurai-dao
@Override
protected Byte doGetValue(ResultSet rs, String columnLabel) throws SQLException {
BigDecimal num = rs.getBigDecimal(columnLabel);
if (num == null) {
return null;
}
return num.byteValue();
}
代码示例来源:origin: org.codehaus.castor/castor-jdo
/**
* {@inheritDoc}
*/
public Object convert(final Object object) {
return new Byte(((BigDecimal) object).byteValue());
}
代码示例来源:origin: jp.dodododo/samurai-dao
@Override
protected Byte doGetValue(ResultSet rs, int columnIndex) throws SQLException {
BigDecimal num = rs.getBigDecimal(columnIndex);
if (num == null) {
return null;
}
return num.byteValue();
}
代码示例来源:origin: org.apache.torque/torque-runtime
/**
* Returns the value of this NumberKey as a byte. This value is subject
* to the conversion rules set out in
* {@link java.math.BigDecimal#byteValue()}
*
* @return the NumberKey converted to a byte
*/
public byte byteValue()
{
return getBigDecimal().byteValue();
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-sql
@Override
@Nullable
public Byte extractOutput(KV<Integer, BigDecimal> accumulator) {
return accumulator.getKey() == 0 ? null : prepareOutput(accumulator).byteValue();
}
代码示例来源:origin: org.apache.openjpa/openjpa-all
@Override
public byte getByte(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.getByte(rs, column);
} catch (SQLException sqle) {
return super.getBigDecimal(rs, column).byteValue();
}
}
代码示例来源:origin: org.apache.openjpa/openjpa-jdbc
@Override
public byte getByte(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.getByte(rs, column);
} catch (SQLException sqle) {
return super.getBigDecimal(rs, column).byteValue();
}
}
代码示例来源:origin: org.apache.openejb.patch/openjpa
@Override
public byte getByte(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.getByte(rs, column);
} catch (SQLException sqle) {
return super.getBigDecimal(rs, column).byteValue();
}
}
代码示例来源:origin: org.apache.openjpa/com.springsource.org.apache.openjpa
public byte getByte(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.getByte(rs, column);
} catch (SQLException sqle) {
return super.getBigDecimal(rs, column).byteValue();
}
}
代码示例来源:origin: org.apache.openejb.patch/openjpa-jdbc
@Override
public byte getByte(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.getByte(rs, column);
} catch (SQLException sqle) {
return super.getBigDecimal(rs, column).byteValue();
}
}
代码示例来源:origin: org.apache.plc4x/plc4j-protocol-driver-base
@Override
public Byte getByte(int index) {
if (!isValidByte(index)) {
throw new PlcIncompatibleDatatypeException(Byte.class, index);
}
return getValue(index).byteValue();
}
代码示例来源:origin: jsonzou/jmockdata
@Override
public Byte mock(DataConfig mockConfig) {
/**
* 若根据正则模拟
*/
if(mockConfig.numberXeger()!=null){
return RandomUtils.nextNumberFromXeger(mockConfig.numberXeger()).byteValue();
}
return (byte) RandomUtils.nextInt(mockConfig.byteRange()[0], mockConfig.byteRange()[1]);
}
内容来源于网络,如有侵权,请联系作者删除!