当前位置: 首页>>代码示例>>Java>>正文


Java BigDecimal.longValue方法代码示例

本文整理汇总了Java中java.math.BigDecimal.longValue方法的典型用法代码示例。如果您正苦于以下问题:Java BigDecimal.longValue方法的具体用法?Java BigDecimal.longValue怎么用?Java BigDecimal.longValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.math.BigDecimal的用法示例。


在下文中一共展示了BigDecimal.longValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseSNS

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Parse the format s.ns. If there is no "." we assume the number represents
 * nanos.
 */
private static @Nullable Long parseSNS(String input) {
    long nbPoints = input.chars().filter(c -> c == '.').count();
    if (nbPoints > 1) {
        /* Only 1 decimal point allowed */
        return null;
    }
    try {
        BigDecimal bd = new BigDecimal(input);
        if (nbPoints == 0) {
            /* Keep the value as nanoseconds. */
        } else {
            /* Parse as seconds then convert to nanos. */
            bd = bd.multiply(NANOS_PER_SEC_BD);
        }
        return bd.longValue();

    } catch (NumberFormatException e) {
        return null;
    }
}
 
开发者ID:lttng,项目名称:lttng-scope,代码行数:25,代码来源:TimestampConversion.java

示例2: getAccountsTotal

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Calculates total in home currency for all accounts
 */
public Total getAccountsTotal(Currency homeCurrency) {
    ExchangeRateProvider rates = getLatestRates();
    List<Account> accounts = em.getAllAccountsList();
    BigDecimal total = BigDecimal.ZERO;
    for (Account account : accounts) {
        if (account.shouldIncludeIntoTotals()) {
            if (account.currency.id == homeCurrency.id) {
                total = total.add(BigDecimal.valueOf(account.totalAmount));
            } else {
                ExchangeRate rate = rates.getRate(account.currency, homeCurrency);
                if (rate == ExchangeRate.NA) {
                    return new Total(homeCurrency, TotalError.lastRateError(account.currency));
                } else {
                    total = total.add(BigDecimal.valueOf(rate.rate*account.totalAmount));
                }
            }
        }
    }
    Total result = new Total(homeCurrency);
    result.balance = total.longValue();
    return result;
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:26,代码来源:DatabaseAdapter.java

示例3: dividePrecise

import java.math.BigDecimal; //导入方法依赖的package包/类
public static Number dividePrecise(Number op1, Number op2) throws Exception {
	BigDecimal result =  null;
	if(op1 instanceof BigDecimal){
		if(op2 instanceof BigDecimal){
			result = ((BigDecimal)op1).divide((BigDecimal)op2, DIVIDE_PRECISION, BigDecimal.ROUND_HALF_UP);
		}else{
			result = ((BigDecimal)op1).divide(new BigDecimal(op2.toString()), DIVIDE_PRECISION, BigDecimal.ROUND_HALF_UP);
		}
	}else{
		if(op2 instanceof BigDecimal){
			result = new BigDecimal(op1.toString()).divide((BigDecimal)op2, DIVIDE_PRECISION, BigDecimal.ROUND_HALF_UP);
		}else{
			result = new BigDecimal(op1.toString()).divide(new BigDecimal(op2.toString()), DIVIDE_PRECISION, BigDecimal.ROUND_HALF_UP);
		}
	}
	if(result.scale() ==0){
		long tempLong =  result.longValue();
		if(tempLong <= Integer.MAX_VALUE && tempLong >= Integer.MIN_VALUE){
			return (int)tempLong;
		}else{
			return tempLong;
		}
	}else{
		return result;
	}
}
 
开发者ID:alibaba,项目名称:QLExpress,代码行数:27,代码来源:OperatorOfNumber.java

示例4: findSeatBalance

import java.math.BigDecimal; //导入方法依赖的package包/类
public Long findSeatBalance(String seat) {
	if (StringUtils.isEmpty(seat)) {
		return null;
	}

	BigDecimal balance = seatRepository.findSeatBalance(seat);
	return balance != null ? balance.longValue() : 0L;
}
 
开发者ID:edylle,项目名称:hockey-game,代码行数:9,代码来源:SeatService.java

示例5: addPrecise

import java.math.BigDecimal; //导入方法依赖的package包/类
public static Number addPrecise(Number op1, Number op2) throws Exception {
	BigDecimal result =  null;
	if(op1 instanceof BigDecimal){
		if(op2 instanceof BigDecimal){
			result =  ((BigDecimal)op1).add((BigDecimal)op2);
		}else{
			result =  ((BigDecimal)op1).add(new BigDecimal(op2.toString()));
		}
	}else{
		if(op2 instanceof BigDecimal){
			result =  new BigDecimal(op1.toString()).add((BigDecimal)op2);
		}else{
			result =  new BigDecimal(op1.toString()).add(new BigDecimal(op2.toString()));
		}
	}
	if(result.scale() ==0){
		long tempLong =  result.longValue();
		if(tempLong <= Integer.MAX_VALUE && tempLong >= Integer.MIN_VALUE){
			return (int)tempLong;
		}else{
			return tempLong;
		}
	}else{
		return result;
	}
	
}
 
开发者ID:alibaba,项目名称:QLExpress,代码行数:28,代码来源:OperatorOfNumber.java

示例6: write

import java.math.BigDecimal; //导入方法依赖的package包/类
public void write(VarBufferPos buffer, BigDecimal bigDecimal)
{
	long lValue = bigDecimal.longValue();
	if(lValue < 0)
		lValue = -lValue;
	writeIntComp4AsLong(buffer, lValue);
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:8,代码来源:VarDefNumIntComp4Long.java

示例7: getTime

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * MAKETIME(h,m,s) is a time function that calculates a time value from the
 * total number of hours, minutes, and seconds. Result: Time value
 */
@Override
public boolean getTime(MySQLTime ltime) {
    long minute = args.get(1).valInt().longValue();
    BigDecimal sec = args.get(2).valDecimal();
    if ((nullValue = (args.get(0).isNullValue() || args.get(1).isNullValue() || args.get(2).isNullValue() || sec == null ||
            minute < 0 || minute > 59))) {
        return true;
    }
    long scdquot = sec.longValue();
    long scdrem = (long) ((sec.doubleValue() - scdquot) * 1000000);
    if ((nullValue = (scdquot < 0 || scdquot > 59 || scdrem < 0))) {
        return true;
    }

    ltime.setZeroTime(MySQLTimestampType.MYSQL_TIMESTAMP_TIME);

    long hour = args.get(0).valInt().longValue();
    /* Check for integer overflows */
    if (hour < 0) {
        ltime.setNeg(true);
    }
    ltime.setHour(((hour < 0 ? -hour : hour)));
    ltime.setMinute(minute);
    ltime.setSecond(scdquot);
    ltime.setSecondPart(scdrem);
    return false;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:32,代码来源:ItemFuncMaketime.java

示例8: testLongFloorMod

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Test FloorMod of long arguments against expected value.
 * The expected value is usually a Long but in some cases  is
 * an ArithmeticException.
 *
 * @param x dividend
 * @param y modulus
 * @param expected expected value
 */
static void testLongFloorMod(long x, long y, Object expected) {
    Object result = doFloorMod(x, y);
    if (!resultEquals(result, expected)) {
        fail("FAIL: long Math.floorMod(%d, %d) = %s; expected %s%n", x, y, result, expected);
    }

    Object strict_result = doStrictFloorMod(x, y);
    if (!resultEquals(strict_result, expected)) {
        fail("FAIL: long StrictMath.floorMod(%d, %d) = %s; expected %s%n", x, y, strict_result, expected);
    }

    try {
        // Verify the result against BigDecimal rounding mode.
        BigDecimal xD = new BigDecimal(x);
        BigDecimal yD = new BigDecimal(y);
        BigDecimal resultD = xD.divide(yD, RoundingMode.FLOOR);
        resultD = resultD.multiply(yD);
        resultD = xD.subtract(resultD);
        long fr = resultD.longValue();
        if (!result.equals(fr)) {
            fail("FAIL: Long.floorMod(%d, %d) = %d is different than BigDecimal result: %d%n", x, y, result, fr);

        }
    } catch (ArithmeticException ae) {
        if (y != 0) {
            fail("FAIL: long Math.floorMod(%d, %d); unexpected ArithmeticException from bigdecimal");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:DivModTests.java

示例9: write

import java.math.BigDecimal; //导入方法依赖的package包/类
public void write(VarBufferPos buffer, BigDecimal bigDecimal)
{
	long l = bigDecimal.longValue();
	if(l < 0)
		l = -l;
	writeIntComp0AsLong(buffer, l);
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:8,代码来源:VarDefNumIntComp0.java

示例10: testLongIntFloorMod

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Test FloorMod of long arguments against expected value.
 * The expected value is usually a Long but in some cases  is
 * an ArithmeticException.
 *
 * @param x dividend
 * @param y modulus
 * @param expected expected value
 */
static void testLongIntFloorMod(long x, int y, Object expected) {
    Object result = doFloorMod(x, y);
    if (!resultEquals(result, expected)) {
        fail("FAIL: long Math.floorMod(%d, %d) = %s; expected %s%n", x, y, result, expected);
    }

    Object strict_result = doStrictFloorMod(x, y);
    if (!resultEquals(strict_result, expected)) {
        fail("FAIL: long StrictMath.floorMod(%d, %d) = %s; expected %s%n", x, y, strict_result, expected);
    }

    try {
        // Verify the result against BigDecimal rounding mode.
        BigDecimal xD = new BigDecimal(x);
        BigDecimal yD = new BigDecimal(y);
        BigDecimal resultD = xD.divide(yD, RoundingMode.FLOOR);
        resultD = resultD.multiply(yD);
        resultD = xD.subtract(resultD);
        long fr = resultD.longValue();
        if (!result.equals(fr)) {
            fail("FAIL: Long.floorMod(%d, %d) = %d is different than BigDecimal result: %d%n", x, y, result, fr);

        }
    } catch (ArithmeticException ae) {
        if (y != 0) {
            fail("FAIL: long Math.floorMod(%d, %d); unexpected ArithmeticException from bigdecimal");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:DivModTests.java

示例11: castToLong

import java.math.BigDecimal; //导入方法依赖的package包/类
public static long castToLong(BigDecimal n)
{
	if (n.compareTo(BigDecimal.valueOf(Long.MAX_VALUE)) > 0)
		throw new ArithmeticException("Numeric value overflow");
	return n.longValue();
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:7,代码来源:CoreTypes.java

示例12: transform_g

import java.math.BigDecimal; //导入方法依赖的package包/类
void transform_g() {
    int precision = formatToken.getPrecision();
    precision = (0 == precision ? 1 : precision);
    formatToken.setPrecision(precision);

    if (0.0 == ((Number) argument).doubleValue()) {
        precision--;
        formatToken.setPrecision(precision);
        transform_f();
        return;
    }

    boolean requireScientificRepresentation = true;
    double d = ((Number) argument).doubleValue();
    d = Math.abs(d);
    if (Double.isInfinite(d)) {
        precision = formatToken.getPrecision();
        precision--;
        formatToken.setPrecision(precision);
        transform_e();
        return;
    }
    BigDecimal b = new BigDecimal(d, new MathContext(precision));
    d = b.doubleValue();
    long l = b.longValue();

    if (d >= 1 && d < Math.pow(10, precision)) {
        if (l < Math.pow(10, precision)) {
            requireScientificRepresentation = false;
            precision -= String.valueOf(l).length();
            precision = precision < 0 ? 0 : precision;
            l = Math.round(d * Math.pow(10, precision + 1));
            if (String.valueOf(l).length() <= formatToken
                    .getPrecision()) {
                precision++;
            }
            formatToken.setPrecision(precision);
        }

    } else {
        l = b.movePointRight(4).longValue();
        if (d >= Math.pow(10, -4) && d < 1) {
            requireScientificRepresentation = false;
            precision += 4 - String.valueOf(l).length();
            l = b.movePointRight(precision + 1).longValue();
            if (String.valueOf(l).length() <= formatToken
                    .getPrecision()) {
                precision++;
            }
            l = b.movePointRight(precision).longValue();
            if (l >= Math.pow(10, precision - 4)) {
                formatToken.setPrecision(precision);
            }
        }
    }
    if (requireScientificRepresentation) {
        precision = formatToken.getPrecision();
        precision--;
        formatToken.setPrecision(precision);
        transform_e();
    } else {
        transform_f();
    }

}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:66,代码来源:LenientFormatter.java

示例13: write

import java.math.BigDecimal; //导入方法依赖的package包/类
public void write(VarBufferPos buffer, BigDecimal bigDecimal)
{
	long lValue = bigDecimal.longValue();
	Pic9Comp3BufferSupport.setFromRightToLeftSignedLong(buffer, m_nNbDigitInteger, m_nTotalSize, lValue);
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:6,代码来源:VarDefFPacNumIntSignComp3.java

示例14: write

import java.math.BigDecimal; //导入方法依赖的package包/类
public void write(VarBufferPos buffer, BigDecimal bigDecimal)
{
	long lValue = bigDecimal.longValue();
	writeSignSeparatedLeadingIntComp0AsLong(buffer, lValue);
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:6,代码来源:VarDefNumIntSignLeadingComp0Long.java

示例15: write

import java.math.BigDecimal; //导入方法依赖的package包/类
public void write(VarBufferPos buffer, BigDecimal bigDecimal)
{
	long l = bigDecimal.longValue();
	m_var.set(l);
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:6,代码来源:VarDefInternalBool.java


注:本文中的java.math.BigDecimal.longValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。