本文整理了Java中java.math.BigDecimal.intValue()
方法的一些代码示例,展示了BigDecimal.intValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.intValue()
方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:intValue
[英]Returns this BigDecimal as an int value. Any fractional part is discarded. If the integral part of this is too big to be represented as an int, then this % 232 is returned.
[中]将此BigDecimal作为int值返回。任何小数部分都将被丢弃。如果此函数的整数部分太大,无法表示为int,则返回此%232。
代码示例来源:origin: prestodb/presto
public static int extractNanosecondDecimal(BigDecimal value, long integer)
{
// !!! 14-Mar-2016, tatu: Somewhat inefficient; should replace with functionally
// equivalent code that just subtracts integral part? (or, measure and show
// there's no difference and do nothing... )
return value.subtract(new BigDecimal(integer)).multiply(ONE_BILLION).intValue();
}
}
代码示例来源: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: Pay-Group/best-pay-sdk
/**
* 元转分
* @param yuan
* @return
*/
public static Integer Yuan2Fen(Double yuan) {
return new BigDecimal(String.valueOf(yuan)).movePointRight(2).intValue();
}
代码示例来源: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());
}
}
代码示例来源:origin: bootique/bootique
public static int extractNanosecondDecimal(BigDecimal value, long integer) {
// !!! 14-Mar-2016, tatu: Somewhat inefficient; should replace with functionally
// equivalent code that just subtracts integral part? (or, measure and show
// there's no difference and do nothing... )
return value.subtract(new BigDecimal(integer)).multiply(ONE_BILLION).intValue();
}
}
代码示例来源:origin: apache/hive
new HiveIntervalDayTime(0, 0, Integer.parseInt(intervalString), 0, 0));
case HiveParser.TOK_INTERVAL_SECOND_LITERAL:
BigDecimal bd = new BigDecimal(intervalString);
BigDecimal bdSeconds = new BigDecimal(bd.toBigInteger());
BigDecimal bdNanos = bd.subtract(bdSeconds);
return new ExprNodeConstantDesc(TypeInfoFactory.intervalDayTimeTypeInfo,
new HiveIntervalDayTime(0, 0, 0, bdSeconds.intValueExact(),
bdNanos.multiply(NANOS_PER_SEC_BD).intValue()));
default:
throw new IllegalArgumentException("Invalid time literal type " + expr.getType());
代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310
/**
* @Deprecated due to potential unbounded latency on some JRE releases.
*/
public static int extractNanosecondDecimal(BigDecimal value, long integer)
{
// !!! 14-Mar-2016, tatu: Somewhat inefficient; should replace with functionally
// equivalent code that just subtracts integral part? (or, measure and show
// there's no difference and do nothing... )
return value.subtract(new BigDecimal(integer)).multiply(ONE_BILLION).intValue();
}
代码示例来源:origin: apache/drill
new HiveIntervalDayTime(0, 0, Integer.parseInt(intervalString), 0, 0));
case HiveParser.TOK_INTERVAL_SECOND_LITERAL:
BigDecimal bd = new BigDecimal(intervalString);
BigDecimal bdSeconds = new BigDecimal(bd.toBigInteger());
BigDecimal bdNanos = bd.subtract(bdSeconds);
return new ExprNodeConstantDesc(TypeInfoFactory.intervalDayTimeTypeInfo,
new HiveIntervalDayTime(0, 0, 0, bdSeconds.intValueExact(),
bdNanos.multiply(NANOS_PER_SEC_BD).intValue()));
default:
throw new IllegalArgumentException("Invalid time literal type " + expr.getType());
代码示例来源:origin: spotbugs/spotbugs
public static void main(String args[]) {
new BigDecimal("1.0");
BigDecimal b = new BigDecimal("2.0");
b.intValue();
"".matches("a");
}
代码示例来源:origin: alipay/sofa-rpc
/**
* 将double与小数相乘,计算结四舍五入保留整数位。
*
* @param num1 数字1
* @param num2 数字2
* @return 数字相乘计算结果
*/
public static int multiply(double num1, double num2) {
BigDecimal num1Bd = new BigDecimal(Double.toString(num1));
BigDecimal num2Bd = new BigDecimal(Double.toString(num2));
MathContext mathContext = new MathContext(num1Bd.precision(), RoundingMode.HALF_UP);
return num1Bd.multiply(num2Bd, mathContext).intValue();
}
代码示例来源:origin: alipay/sofa-rpc
/**
* 将double与小数相乘,计算结四舍五入保留整数位。
*
* @param num1 数字1
* @param num2 数字2
* @return 数字相乘计算结果
*/
public static int multiply(double num1, double num2) {
BigDecimal num1Bd = new BigDecimal(Double.toString(num1));
BigDecimal num2Bd = new BigDecimal(Double.toString(num2));
MathContext mathContext = new MathContext(num1Bd.precision(), RoundingMode.HALF_UP);
return num1Bd.multiply(num2Bd, mathContext).intValue();
}
代码示例来源:origin: apache/incubator-shardingsphere
/**
* Round half up.
*
* @param obj object to be converted
* @return rounded half up number
*/
public static int roundHalfUp(final Object obj) {
if (obj instanceof Short) {
return (short) obj;
}
if (obj instanceof Integer) {
return (int) obj;
}
if (obj instanceof Long) {
return ((Long) obj).intValue();
}
if (obj instanceof Double) {
return new BigDecimal((double) obj).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
}
if (obj instanceof Float) {
return new BigDecimal((float) obj).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
}
if (obj instanceof String) {
return new BigDecimal((String) obj).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
}
throw new ShardingException("Invalid value to transfer: %s", obj);
}
代码示例来源:origin: apache/hive
public static Timestamp doubleToTimestamp(double f) {
try {
long seconds = (long) f;
// We must ensure the exactness of the double's fractional portion.
// 0.6 as the fraction part will be converted to 0.59999... and
// significantly reduce the savings from binary serialization
BigDecimal bd = new BigDecimal(String.valueOf(f));
bd = bd.subtract(new BigDecimal(seconds)).multiply(new BigDecimal(1000000000));
int nanos = bd.intValue();
// Convert to millis
long millis = seconds * 1000;
if (nanos < 0) {
millis -= 1000;
nanos += 1000000000;
}
Timestamp t = new Timestamp(millis);
// Set remaining fractional portion to nanos
t.setNanos(nanos);
return t;
} catch (NumberFormatException nfe) {
return null;
} catch (IllegalArgumentException iae) {
return null;
}
}
代码示例来源:origin: apache/hive
public static Timestamp doubleToTimestamp(double f) {
try {
long seconds = (long) f;
// We must ensure the exactness of the double's fractional portion.
// 0.6 as the fraction part will be converted to 0.59999... and
// significantly reduce the savings from binary serialization
BigDecimal bd = new BigDecimal(String.valueOf(f));
bd = bd.subtract(new BigDecimal(seconds)).multiply(new BigDecimal(1000000000));
int nanos = bd.intValue();
// Convert to millis
long millis = seconds * 1000;
if (nanos < 0) {
millis -= 1000;
nanos += 1000000000;
}
return Timestamp.ofEpochMilli(millis, nanos);
} catch (IllegalArgumentException | DateTimeException nfe) {
return null;
}
}
代码示例来源:origin: json-path/JsonPath
private static Number unwrapNumber(final Number n) {
Number unwrapped;
if (!isPrimitiveNumber(n)) {
BigDecimal bigDecimal = new BigDecimal(n.toString());
if (bigDecimal.scale() <= 0) {
if (bigDecimal.compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) {
unwrapped = bigDecimal.intValue();
} else if (bigDecimal.compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0){
unwrapped = bigDecimal.longValue();
} else {
unwrapped = bigDecimal;
}
} else {
final double doubleValue = bigDecimal.doubleValue();
if (BigDecimal.valueOf(doubleValue).compareTo(bigDecimal) != 0) {
unwrapped = bigDecimal;
} else {
unwrapped = doubleValue;
}
}
} else {
unwrapped = n;
}
return unwrapped;
}
代码示例来源:origin: alibaba/druid
public Object eval(SQLEvalVisitor visitor, SQLMethodInvokeExpr x) {
if (x.getParameters().size() == 0) {
return SQLEvalVisitor.EVAL_ERROR;
}
StringBuffer buf = new StringBuffer(x.getParameters().size());
for (SQLExpr param : x.getParameters()) {
param.accept(visitor);
Object paramValue = param.getAttributes().get(EVAL_VALUE);
if (paramValue instanceof Number) {
int charCode = ((Number) paramValue).intValue();
buf.append((char) charCode);
} else if (paramValue instanceof String) {
try {
int charCode = new BigDecimal((String) paramValue).intValue();
buf.append((char) charCode);
} catch (NumberFormatException e) {
}
} else {
return SQLEvalVisitor.EVAL_ERROR;
}
}
return buf.toString();
}
}
代码示例来源:origin: apache/hive
public static Timestamp decimalToTimestamp(HiveDecimalV1 dec) {
try {
BigDecimal nanoInstant = dec.bigDecimalValue().multiply(BILLION_BIG_DECIMAL);
int nanos = nanoInstant.remainder(BILLION_BIG_DECIMAL).intValue();
if (nanos < 0) {
nanos += 1000000000;
}
long seconds =
nanoInstant.subtract(new BigDecimal(nanos)).divide(BILLION_BIG_DECIMAL).longValue();
Timestamp t = new Timestamp(seconds * 1000);
t.setNanos(nanos);
return t;
} catch (NumberFormatException nfe) {
return null;
} catch (IllegalArgumentException iae) {
return null;
}
}
代码示例来源:origin: google/ExoPlayer
Integer.parseInt(matcher.group(6)));
if (!TextUtils.isEmpty(matcher.group(8))) {
final BigDecimal bd = new BigDecimal("0." + matcher.group(8));
dateTime.set(Calendar.MILLISECOND, bd.movePointRight(3).intValue());
代码示例来源:origin: apache/hive
public static Timestamp decimalToTimestamp(HiveDecimalV1 dec) {
try {
BigDecimal nanoInstant = dec.bigDecimalValue().multiply(BILLION_BIG_DECIMAL);
int nanos = nanoInstant.remainder(BILLION_BIG_DECIMAL).intValue();
if (nanos < 0) {
nanos += 1000000000;
}
long seconds =
nanoInstant.subtract(new BigDecimal(nanos)).divide(BILLION_BIG_DECIMAL).longValue();
return Timestamp.ofEpochSecond(seconds, nanos);
} catch (IllegalArgumentException | DateTimeException nfe) {
return null;
}
}
代码示例来源:origin: debezium/debezium
BigDecimal bigSeconds = BigDecimal.valueOf(Math.abs(durationInMillis)).divide(new BigDecimal(1000));
int minutes = bigSeconds.intValue() / 60;
内容来源于网络,如有侵权,请联系作者删除!