本文整理了Java中java.math.BigDecimal.toBigInteger()
方法的一些代码示例,展示了BigDecimal.toBigInteger()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.toBigInteger()
方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:toBigInteger
[英]Returns this BigDecimal as a big integer instance. A fractional part is discarded.
[中]将此BigDecimal作为大整数实例返回。一小部分被丢弃。
代码示例来源:origin: protostuff/protostuff
@Override
public BigInteger toBigInteger()
{
return new BigDecimal(value).toBigInteger();
}
代码示例来源:origin: prestodb/presto
protected void convertNumberToBigInteger() throws IOException
{
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
// here it'll just get truncated, no exceptions thrown
_numberBigInt = _numberBigDecimal.toBigInteger();
} else if ((_numTypesValid & NR_LONG) != 0) {
_numberBigInt = BigInteger.valueOf(_numberLong);
} else if ((_numTypesValid & NR_INT) != 0) {
_numberBigInt = BigInteger.valueOf(_numberInt);
} else if ((_numTypesValid & NR_DOUBLE) != 0) {
_numberBigInt = BigDecimal.valueOf(_numberDouble).toBigInteger();
} else {
_throwInternal();
}
_numTypesValid |= NR_BIGINT;
}
代码示例来源:origin: spring-projects/spring-framework
if (number instanceof BigDecimal) {
return (T) ((BigDecimal) number).toBigInteger();
return (T) BigInteger.valueOf(number.longValue());
return (T) new BigDecimal(number.toString());
代码示例来源:origin: org.elasticsearch/elasticsearch
/** Return the long that {@code stringValue} stores or throws an exception if the
* stored value cannot be converted to a long that stores the exact same
* value and {@code coerce} is false. */
public static long toLong(String stringValue, boolean coerce) {
try {
return Long.parseLong(stringValue);
} catch (NumberFormatException e) {
// we will try again with BigDecimal
}
final BigInteger bigIntegerValue;
try {
BigDecimal bigDecimalValue = new BigDecimal(stringValue);
bigIntegerValue = coerce ? bigDecimalValue.toBigInteger() : bigDecimalValue.toBigIntegerExact();
} catch (ArithmeticException e) {
throw new IllegalArgumentException("Value [" + stringValue + "] has a decimal part");
} catch (NumberFormatException e) {
throw new IllegalArgumentException("For input string: \"" + stringValue + "\"");
}
if (bigIntegerValue.compareTo(MAX_LONG_VALUE) > 0 || bigIntegerValue.compareTo(MIN_LONG_VALUE) < 0) {
throw new IllegalArgumentException("Value [" + stringValue + "] is out of range for a long");
}
return bigIntegerValue.longValue();
}
代码示例来源:origin: thymeleaf/thymeleaf
static Number computeValue(final String value) {
final BigDecimal bigDecimalValue = new BigDecimal(value);
if (bigDecimalValue.scale() > 0) {
return bigDecimalValue;
}
return bigDecimalValue.toBigInteger();
}
代码示例来源:origin: loklak/loklak_server
return ((BigDecimal) val).toBigInteger();
return new BigDecimal(((Number) val).doubleValue()).toBigInteger();
return BigInteger.valueOf(((Number) val).longValue());
return new BigDecimal(valStr).toBigInteger();
代码示例来源:origin: redisson/redisson
protected void convertNumberToBigInteger() throws IOException
{
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
// here it'll just get truncated, no exceptions thrown
_numberBigInt = _numberBigDecimal.toBigInteger();
} else if ((_numTypesValid & NR_LONG) != 0) {
_numberBigInt = BigInteger.valueOf(_numberLong);
} else if ((_numTypesValid & NR_INT) != 0) {
_numberBigInt = BigInteger.valueOf(_numberInt);
} else if ((_numTypesValid & NR_DOUBLE) != 0) {
_numberBigInt = BigDecimal.valueOf(_numberDouble).toBigInteger();
} else {
_throwInternal();
}
_numTypesValid |= NR_BIGINT;
}
代码示例来源:origin: stackoverflow.com
BigInteger k = new BigDecimal(doubleValue).toBigInteger();
代码示例来源:origin: loklak/loklak_server
return ((BigDecimal) val).toBigInteger();
return new BigDecimal(((Number) val).doubleValue()).toBigInteger();
return BigInteger.valueOf(((Number) val).longValue());
return new BigDecimal(valStr).toBigInteger();
代码示例来源:origin: immutables/immutables
@Override
public BigInteger getBigIntegerValue() throws IOException {
final Number value = getNumberValue();
if (value instanceof BigInteger) {
return (BigInteger) value;
} else if (value instanceof BigDecimal) {
return ((BigDecimal) value).toBigInteger();
}
return BigInteger.valueOf(value.longValue());
}
代码示例来源:origin: org.codehaus.groovy/groovy
private boolean isIntegral(Number stepSize) {
BigDecimal tempStepSize = new BigDecimal(stepSize.toString());
return tempStepSize.equals(new BigDecimal(tempStepSize.toBigInteger()));
}
代码示例来源:origin: org.codehaus.groovy/groovy
final BigInteger toTemp = new BigInteger(to.toString());
final BigInteger toNum = inclusive ? toTemp : toTemp.subtract(BigInteger.ONE);
final BigInteger sizeNum = new BigDecimal(toNum.subtract(fromNum)).divide(new BigDecimal(stepSize.longValue()), BigDecimal.ROUND_DOWN).toBigInteger().add(BigInteger.ONE);
tempsize = sizeNum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == -1 ? sizeNum.intValue() : Integer.MAX_VALUE;
shortcut = true;
} else if (((from instanceof BigDecimal || from instanceof BigInteger) && to instanceof Number) ||
((to instanceof BigDecimal || to instanceof BigInteger) && from instanceof Number)) {
final BigDecimal fromNum = new BigDecimal(from.toString());
final BigDecimal toTemp = new BigDecimal(to.toString());
final BigDecimal toNum = inclusive ? toTemp : toTemp.subtract(new BigDecimal("1.0"));
final BigInteger sizeNum = toNum.subtract(fromNum).divide(new BigDecimal(stepSize.longValue()), BigDecimal.ROUND_DOWN).toBigInteger().add(BigInteger.ONE);
tempsize = sizeNum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == -1 ? sizeNum.intValue() : Integer.MAX_VALUE;
shortcut = true;
代码示例来源:origin: prestodb/presto
@Override
public BigInteger getBigIntegerValue() throws IOException
{
Number n = getNumberValue();
if (n instanceof BigInteger) {
return (BigInteger) n;
}
if (getNumberType() == NumberType.BIG_DECIMAL) {
return ((BigDecimal) n).toBigInteger();
}
// int/long is simple, but let's also just truncate float/double:
return BigInteger.valueOf(n.longValue());
}
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* Transform this Number into a BigInteger.
*
* @param self a Number
* @return a BigInteger
* @since 1.0
*/
public static BigInteger toBigInteger(Number self) {
if (self instanceof BigInteger) {
return (BigInteger) self;
} else if (self instanceof BigDecimal) {
return ((BigDecimal) self).toBigInteger();
} else if (self instanceof Double) {
return new BigDecimal((Double)self).toBigInteger();
} else if (self instanceof Float) {
return new BigDecimal((Float)self).toBigInteger();
} else {
return new BigInteger(Long.toString(self.longValue()));
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
final BigInteger sizeNum = toNum.subtract(fromNum).add(new BigInteger("1"));
tempsize = sizeNum.intValue();
if (!BigInteger.valueOf(tempsize).equals(sizeNum)) {
tempsize = Integer.MAX_VALUE;
((to instanceof BigDecimal || to instanceof BigInteger) && from instanceof Number)) {
final BigDecimal fromNum = new BigDecimal(from.toString());
final BigDecimal toNum = new BigDecimal(to.toString());
final BigInteger sizeNum = toNum.subtract(fromNum).add(new BigDecimal(1.0)).toBigInteger();
tempsize = sizeNum.intValue();
if (!BigInteger.valueOf(tempsize).equals(sizeNum)) {
tempsize = Integer.MAX_VALUE;
代码示例来源:origin: FasterXML/jackson-core
protected void convertNumberToBigInteger() throws IOException
{
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
// here it'll just get truncated, no exceptions thrown
_numberBigInt = _numberBigDecimal.toBigInteger();
} else if ((_numTypesValid & NR_LONG) != 0) {
_numberBigInt = BigInteger.valueOf(_numberLong);
} else if ((_numTypesValid & NR_INT) != 0) {
_numberBigInt = BigInteger.valueOf(_numberInt);
} else if ((_numTypesValid & NR_DOUBLE) != 0) {
_numberBigInt = BigDecimal.valueOf(_numberDouble).toBigInteger();
} else {
_throwInternal();
}
_numTypesValid |= NR_BIGINT;
}
代码示例来源:origin: apache/hive
@Override
protected HiveIntervalDayTime getIntervalDayTime(String arg) {
BigDecimal bd = new BigDecimal(arg);
BigDecimal bdSeconds = new BigDecimal(bd.toBigInteger());
BigDecimal bdNanos = bd.subtract(bdSeconds);
return new HiveIntervalDayTime(0, 0, 0, bdSeconds.intValueExact(),
bdNanos.multiply(NANOS_PER_SEC_BD).intValue());
}
}
代码示例来源:origin: org.freemarker/freemarker
return n;
} else if (n instanceof BigInteger) {
return new BigDecimal((BigInteger) n);
} else if (n instanceof Long) {
return new BigDecimal(n.doubleValue());
return ((OverloadedNumberUtil.IntegerBigDecimal) n).bigIntegerValue();
} else if (n instanceof BigDecimal) {
return ((BigDecimal) n).toBigInteger();
} else {
return BigInteger.valueOf(n.longValue());
代码示例来源:origin: org.codehaus.jackson/jackson-core-asl
protected void convertNumberToBigInteger()
throws IOException, JsonParseException
{
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
// here it'll just get truncated, no exceptions thrown
_numberBigInt = _numberBigDecimal.toBigInteger();
} else if ((_numTypesValid & NR_LONG) != 0) {
_numberBigInt = BigInteger.valueOf(_numberLong);
} else if ((_numTypesValid & NR_INT) != 0) {
_numberBigInt = BigInteger.valueOf(_numberInt);
} else if ((_numTypesValid & NR_DOUBLE) != 0) {
_numberBigInt = BigDecimal.valueOf(_numberDouble).toBigInteger();
} else {
_throwInternal(); // should never get here
}
_numTypesValid |= NR_BIGINT;
}
代码示例来源:origin: apache/drill
@Override
protected HiveIntervalDayTime getIntervalDayTime(String arg) {
BigDecimal bd = new BigDecimal(arg);
BigDecimal bdSeconds = new BigDecimal(bd.toBigInteger());
BigDecimal bdNanos = bd.subtract(bdSeconds);
return new HiveIntervalDayTime(0, 0, 0, bdSeconds.intValueExact(),
bdNanos.multiply(NANOS_PER_SEC_BD).intValue());
}
}
内容来源于网络,如有侵权,请联系作者删除!