本文整理汇总了Java中java.math.BigDecimal.toBigInteger方法的典型用法代码示例。如果您正苦于以下问题:Java BigDecimal.toBigInteger方法的具体用法?Java BigDecimal.toBigInteger怎么用?Java BigDecimal.toBigInteger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigDecimal
的用法示例。
在下文中一共展示了BigDecimal.toBigInteger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBinary
import java.math.BigDecimal; //导入方法依赖的package包/类
String getBinary(BigDecimal fl) throws Exception{
BigInteger fi = fl.toBigInteger();
BigInteger rm;
String response="";
while(fi.compareTo(toDeno)>=0){
rm=fi.remainder(toDeno);
if(rm.compareTo(BigInteger.ZERO)==0)
response='0'+","+response;
else
response=rm.toString()+","+response;
fi=fi.subtract(rm).divide(toDeno);
}
response = fi.toString()+","+response;
if(response.endsWith(","))
response=response.substring(0,response.length()-1);
return response;
}
示例2: getBinary
import java.math.BigDecimal; //导入方法依赖的package包/类
String getBinary(BigDecimal fl) throws Exception{
BigInteger fi = fl.toBigInteger();
BigInteger rm;
String response="";
while(fi.compareTo(tWO)>=0){
rm=fi.remainder(tWO);
if(rm.compareTo(BigInteger.ZERO)==0)
response='0'+response;
else
response='1'+response;
fi=fi.subtract(rm).divide(tWO);
}
int precisionCorrection=(response.length()-response.length()%10)/10;
localMC=new MathContext(jc.MC.getPrecision()+precisionCorrection,jc.MC.getRoundingMode());
return fi.toString()+response;
}
示例3: intOp
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigInteger intOp() {
BigInteger result;
Item.ItemResult i = args.get(0).resultType();
if (i == Item.ItemResult.INT_RESULT) {
result = args.get(0).valInt();
nullValue = args.get(0).isNullValue();
} else if (i == Item.ItemResult.DECIMAL_RESULT) {
BigDecimal dec = decimalOp();
if (dec == null)
result = BigInteger.ZERO;
else
result = dec.toBigInteger();
} else {
result = realOp().toBigInteger();
}
return result;
}
示例4: intOp
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigInteger intOp() {
BigInteger result;
ItemResult i = args.get(0).resultType();
if (i == ItemResult.INT_RESULT) {
result = args.get(0).valInt();
nullValue = args.get(0).isNullValue();
} else if (i == ItemResult.DECIMAL_RESULT) {
BigDecimal dec = decimalOp();
if (dec == null)
result = BigInteger.ZERO;
else
result = dec.toBigInteger();
} else {
result = realOp().toBigInteger();
}
return result;
}
示例5: createNew
import java.math.BigDecimal; //导入方法依赖的package包/类
private TransactionFormData createNew(TransactionFormData formData) {
String fromAddress = formData.getFrom().getValue();
String fromPassword = BEANS.get(IAccountService.class).getPassword(fromAddress);
Account from = BEANS.get(EthereumService.class).getWallet(fromAddress, fromPassword);
String to = formData.getTo().getValue();
BigInteger amountWei = convertToWei(formData.getAmount().getValue());
String data = formData.getData().getValue();
BigDecimal n = formData.getNonce().getValue();
BigDecimal gp = formData.getGasPrice().getValue();
BigDecimal gl = formData.getGasLimit().getValue();
BigInteger nonce = n == null ? null : n.toBigInteger();
BigInteger gasPrice = gp == null ? null : gp.toBigInteger();
BigInteger gasLimit = gl == null ? null : gl.toBigInteger();
BEANS.get(EthereumService.class).createTransaction(from, to, amountWei, data, nonce, gasPrice, gasLimit);
return formData;
}
示例6: decodeText
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public Number decodeText(int len, ByteBuf buff) {
// Todo optimize that
CharSequence cs = buff.readCharSequence(len, StandardCharsets.UTF_8);
BigDecimal big = new BigDecimal(cs.toString());
// julien : that does not seem consistent to either return a Double or BigInteger
if (big.scale() == 0) {
return big.toBigInteger();
} else {
// we might loose precision here
return big.doubleValue();
}
}
示例7: baseToSubunit
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Base - taken to mean default unit for a currency e.g. ETH, DOLLARS
* Subunit - taken to mean subdivision of base e.g. WEI, CENTS
*
* @param baseAmountStr - decimal amonut in base unit of a given currency
* @param decimals - decimal places used to convert to subunits
* @return amount in subunits
*/
public static BigInteger baseToSubunit(String baseAmountStr, int decimals) {
assert(decimals >= 0);
BigDecimal baseAmount = new BigDecimal(baseAmountStr);
BigDecimal subunitAmount = baseAmount.multiply(BigDecimal.valueOf(10).pow(decimals));
try {
return subunitAmount.toBigIntegerExact();
} catch (ArithmeticException ex) {
assert(false);
return subunitAmount.toBigInteger();
}
}
示例8: valInt
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigInteger valInt() {
if (hybridType == ItemResult.DECIMAL_RESULT) {
BigDecimal val = decimalOp();
if (val == null)
return BigInteger.ZERO;
return val.toBigInteger();
} else if (hybridType == ItemResult.INT_RESULT) {
return intOp();
} else if (hybridType == ItemResult.REAL_RESULT) {
return realOp().toBigInteger();
} else if (hybridType == ItemResult.STRING_RESULT) {
FieldTypes i = fieldType();
if (i == FieldTypes.MYSQL_TYPE_DATE) {
return new BigDecimal(valIntFromDate()).toBigInteger();
} else if (i == FieldTypes.MYSQL_TYPE_DATETIME || i == FieldTypes.MYSQL_TYPE_TIMESTAMP) {
return new BigDecimal(valIntFromDatetime()).toBigInteger();
} else if (i == FieldTypes.MYSQL_TYPE_TIME) {
return new BigDecimal(valIntFromTime()).toBigInteger();
}
String res = strOp();
if (res == null)
return BigInteger.ZERO;
try {
return new BigInteger(res);
} catch (Exception e) {
LOGGER.info(res + " to BigInteger error!", e);
}
}
return BigInteger.ZERO;
}
示例9: valInt
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigInteger valInt() {
BigDecimal tmp = valDecimal();
if (nullValue)
return BigInteger.ZERO;
return tmp.toBigInteger();
}
示例10: getDecimalRound
import java.math.BigDecimal; //导入方法依赖的package包/类
private BigDecimal getDecimalRound(BigDecimal value, int round) {
String sVal = value.toString();
if (!sVal.contains(".") || round < 0) {
BigInteger bi = value.toBigInteger();
return new BigDecimal(getIntRound(bi, round));
} else {
return value.setScale(round, RoundingMode.FLOOR);
}
}
示例11: valInt
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigInteger valInt() {
/*
* Perform division using DECIMAL math if either of the operands has a
* non-integer type
*/
if (args.get(0).resultType() != ItemResult.INT_RESULT ||
args.get(1).resultType() != ItemResult.INT_RESULT) {
BigDecimal val0p = args.get(0).valDecimal();
if (args.get(0).isNull())
return BigInteger.ZERO;
BigDecimal val1p = args.get(1).valDecimal();
if (args.get(1).isNull())
return BigInteger.ZERO;
try {
BigDecimal result = val0p.divideToIntegralValue(val1p);
return result.toBigInteger();
} catch (ArithmeticException ae) {
return BigInteger.ZERO;
}
} else {
BigInteger val0 = args.get(0).valInt();
BigInteger val1 = args.get(1).valInt();
if (args.get(0).isNull() || args.get(1).isNull())
return BigInteger.ZERO;
if (val1.equals(BigInteger.ZERO)) {
signalDivideByNull();
return BigInteger.ZERO;
}
return val0.divide(val1);
}
}
示例12: castToBigInteger
import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigInteger castToBigInteger(double d)
{
BigDecimal deci = new BigDecimal( d );
return deci.toBigInteger();
}
示例13: toInt
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigInteger toInt(BigDecimal arg) {
return arg.toBigInteger();
}
示例14: getNullableResult
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigInteger getNullableResult(ResultSet rs, String columnName) throws SQLException {
BigDecimal bigDecimal = rs.getBigDecimal(columnName);
return bigDecimal == null ? null : bigDecimal.toBigInteger();
}
示例15: toWei
import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigInteger toWei(BigDecimal number, Unit unit) {
BigDecimal weiFactor = unit.getWeiFactor();
BigDecimal multiply = weiFactor.multiply(number);
return multiply.toBigInteger();
}