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


Java BigDecimal.divide方法代码示例

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


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

示例1: doMath

import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigDecimal doMath(BigDecimal valueOne, Math operator, BigDecimal valueTwo)
{
	switch (operator)
	{
		case SUM:
			return valueOne.add(valueTwo);
		case SUBTRACT:
			return valueOne.subtract(valueTwo);
		case MULTIPLY:
			return valueOne.multiply(valueTwo);
		case DIVIDE:
			return valueOne.divide(valueTwo, 256, RoundingMode.CEILING);
		default:
			return new BigDecimal(0);
	}
}
 
开发者ID:DirkDeVisser,项目名称:pifuck,代码行数:17,代码来源:BasicBigDecimal.java

示例2: testItem_0062

import java.math.BigDecimal; //导入方法依赖的package包/类
public void testItem_0062()
{
    BigDecimal alpha = new BigDecimal(new BigInteger("1000"), 0);
    BigDecimal beta = new BigDecimal(new BigInteger("70"), 2);
    BigDecimal gamma = alpha.divide(beta, BigDecimal.ROUND_DOWN);
    gamma.setScale(1, BigDecimal.ROUND_DOWN);
    Assert.assertEquals("1428", gamma.toString());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:9,代码来源:TestSuite063.java

示例3: calculateSVScalingFactor

import java.math.BigDecimal; //导入方法依赖的package包/类
private static double calculateSVScalingFactor(Collection<MRVMBidder> bidders) {
    MRVMBidder biggestAlphaBidder = bidders.stream().max(Comparator.comparing(b -> b.getAlpha())).get();
    MRVMRegionsMap.Region biggestRegion = bidders.stream().findAny().get().getWorld().getRegionsMap().getRegions().stream()
            .max(Comparator.comparing(r -> r.getPopulation())).get();
    BigDecimal biggestAlpha = biggestAlphaBidder.getAlpha();
    BigDecimal biggestPopulation = BigDecimal.valueOf(biggestRegion.getPopulation());
    BigDecimal biggestC = bidders.stream().findAny().get().getWorld().getMaximumRegionalCapacity();
    BigDecimal securityBuffer = BigDecimal.valueOf(100000);
    BigDecimal biggestSv = biggestAlpha.multiply(biggestPopulation).multiply(biggestC).add(securityBuffer);
    BigDecimal MIP_MAX_VALUE = BigDecimal.valueOf(MIP.MAX_VALUE);
    BigDecimal proposedScalingFactor = biggestSv.divide(MIP_MAX_VALUE, RoundingMode.HALF_DOWN);
    if(proposedScalingFactor.compareTo(BigDecimal.ONE) <= 0){
        return 1.;
    }
    return Math.round(proposedScalingFactor.doubleValue())+1;
}
 
开发者ID:spectrumauctions,项目名称:sats-opt,代码行数:17,代码来源:Scalor.java

示例4: doFunction

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public Object doFunction(Object object, String property,WorkingMemory workingMemory) {
	Collection<?> list=null;
	if(object instanceof Collection){
		list=(Collection<?>)object;
	}else{
		throw new RuleException("Function[avg] parameter must be java.util.Collection type.");
	}
	BigDecimal total=null;
	for(Object obj:list){
		Object pvalue=Utils.getObjectProperty(obj, property);
		BigDecimal a=Utils.toBigDecimal(pvalue);
		if(total==null){
			total=a;
		}else{
			total=total.add(a);
		}
	}
	BigDecimal avgvalue=total.divide(new BigDecimal(list.size()),12,BigDecimal.ROUND_HALF_UP);
	return avgvalue.doubleValue();
}
 
开发者ID:youseries,项目名称:urule,代码行数:22,代码来源:AvgFunctionDescriptor.java

示例5: calc

import java.math.BigDecimal; //导入方法依赖的package包/类
private int calc(int current, String walletAddress, BigDecimal tokenNoDiscount) throws ExceedingException, ToHighAmountException {
    for(int i=0;i<PHASE.length-1;i++) {
        if (current < PHASE[i+1] && current >= PHASE[i]) {
            BigDecimal tokenDiscount = tokenNoDiscount.divide(BigDecimal.valueOf(PHASE_PRICE[i]), MathContext.DECIMAL64);
            if(tokenDiscount.intValue() > PHASE[1]) {
                //upper limit for max. tokens is 2.1mio
                throw new ToHighAmountException(tokenDiscount);
            }
            if (current + tokenDiscount.intValue() > PHASE[i+1]) {
                //special case, boundaries!
                BigDecimal totalTokens = tokenDiscount;
                tokenDiscount = BigDecimal.valueOf(PHASE[i+1] - current);
                tokenNoDiscount = totalTokens.subtract(tokenDiscount, MathContext.DECIMAL64).multiply(BigDecimal.valueOf(PHASE_PRICE[i]), MathContext.DECIMAL64);
                updateMap(walletAddress, tokenDiscount.intValue());
                current += tokenDiscount.intValue();
                if(i == PHASE.length - 2) {
                    throw new ExceedingException(tokenNoDiscount, current);
                }
            } else {
                updateMap(walletAddress, tokenDiscount.intValue());
                current += tokenDiscount.intValue();
                return current;
            }
        }
    }
    return current;
}
 
开发者ID:modum-io,项目名称:tokenapp-backend,代码行数:28,代码来源:Minting.java

示例6: main

import java.math.BigDecimal; //导入方法依赖的package包/类
public static void main(String[] args) {

    SquareRootOfBigIntegerExample SquareRootOfBigIntegerExample =
            new SquareRootOfBigIntegerExample();
    String n = "";

    MathContext mc = new MathContext(0, RoundingMode.DOWN);
    mc = MathContext.DECIMAL32;

    BigInteger my2P100000 = new BigInteger("0");
    BigInteger two = new BigInteger("2");
    BigInteger one = new BigInteger("1");

    my2P100000 = two.shiftLeft(2000 - 1);

    System.out.println("2^2000 --  Step 1");
    System.out.println("Value of 2^2,000 " + my2P100000);
    System.out.println("");
    System.out.println("Finding the Square Root of 2^2000");

    String mys = my2P100000 + "";
    n = (mys);
    int firsttime = 0;

    BigDecimal myNumber = new BigDecimal(n);
    BigDecimal g = new BigDecimal("1");
    BigDecimal my2 = new BigDecimal("2");
    BigDecimal epsilon = new BigDecimal("0.0000000001");

    BigDecimal nByg = myNumber.divide(g, 9, BigDecimal.ROUND_FLOOR);

    //Get the value of n/g
    BigDecimal nBygPlusg = nByg.add(g);

    //Get the value of "n/g + g
    BigDecimal nBygPlusgHalf = nBygPlusg.divide(my2, 9, BigDecimal.ROUND_FLOOR);

    //Get the value of (n/g + g)/2
    BigDecimal saveg = nBygPlusgHalf;
    firsttime = 99;

    do {
      g = nBygPlusgHalf;
      nByg = myNumber.divide(g, 9, BigDecimal.ROUND_FLOOR);
      nBygPlusg = nByg.add(g);
      nBygPlusgHalf = nBygPlusg.divide(my2, 9, BigDecimal.ROUND_FLOOR);
      BigDecimal savegdiff = saveg.subtract(nBygPlusgHalf);

      if (savegdiff.compareTo(epsilon) == -1) {
        firsttime = 0;
      } else {
        saveg = nBygPlusgHalf;
      }

    } while (firsttime > 1);

    System.out.println(
            "For " + mys + "\nLength: " + mys.length() + "\nThe Square Root is " + saveg);
  }
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:60,代码来源:SquareRootOfBigIntegerExample.java

示例7: getStockAvailabilityPeriod

import java.math.BigDecimal; //导入方法依赖的package包/类
public BigDecimal getStockAvailabilityPeriod(BigDecimal cr, BigDecimal stk) {
  BigDecimal consumptionRate = BigUtil.getZeroIfNull(cr);
  if (BigUtil.greaterThanZero(consumptionRate)) {
    return stk.divide(consumptionRate, 3, BigDecimal.ROUND_HALF_UP);
  }
  return BigDecimal.ZERO;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:8,代码来源:InventoryManagementServiceImpl.java

示例8: testItem_0030

import java.math.BigDecimal; //导入方法依赖的package包/类
public void testItem_0030()
{
    BigDecimal alpha = new BigDecimal("1000");
    BigDecimal beta = new BigDecimal("0.70").setScale(2);
    BigDecimal gamma = alpha.divide(beta, BigDecimal.ROUND_DOWN);
    gamma.setScale(2);
    Assert.assertEquals("1428", gamma.toString());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:9,代码来源:TestSuite063.java

示例9: testItem_0061

import java.math.BigDecimal; //导入方法依赖的package包/类
public void testItem_0061()
{
    BigDecimal alpha = new BigDecimal("1000").setScale(0);
    BigDecimal beta = new BigDecimal("0.70").setScale(2);
    BigDecimal gamma = alpha.divide(beta, BigDecimal.ROUND_DOWN);
    gamma.setScale(1, BigDecimal.ROUND_DOWN);
    Assert.assertEquals("1428", gamma.toString());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:9,代码来源:TestSuite063.java

示例10: 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

示例11: testItem_0058

import java.math.BigDecimal; //导入方法依赖的package包/类
public void testItem_0058()
{
    BigDecimal alpha = new BigDecimal("1000");
    BigDecimal beta = new BigDecimal("0.70").setScale(2);
    BigDecimal gamma = alpha.divide(beta, BigDecimal.ROUND_DOWN);
    gamma.setScale(2, BigDecimal.ROUND_DOWN);
    Assert.assertEquals("1428", gamma.toString());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:9,代码来源:TestSuite063.java

示例12: evaluate

import java.math.BigDecimal; //导入方法依赖的package包/类
public boolean evaluate(EvaluationContext context,Object obj,List<Object> allMatchedObjects){
	ExprValue value=computeValue(context, obj, allMatchedObjects);
	int total=value.getTotal(),match=value.getMatch(),notMatch=value.getNotMatch();
	switch(statisticType){
	case none:
		if(notMatch==0){
			return true;
		}else{
			return false;
		}
	case amount:
		if(match==amount){
			return true;
		}else{
			return false;
		}
	case percent:
		BigDecimal left=new BigDecimal(match);
		BigDecimal currentPercent=left.divide(new BigDecimal(total),4,BigDecimal.ROUND_HALF_UP);
		int result=currentPercent.compareTo((new BigDecimal(percent)).divide(new BigDecimal(100)));
		if(result==0){
			return true;
		}else{
			return false;
		}
	}
	return false;
}
 
开发者ID:youseries,项目名称:urule,代码行数:29,代码来源:AllLeftPart.java

示例13: LinearFunction

import java.math.BigDecimal; //导入方法依赖的package包/类
public LinearFunction(BigDecimal x1, BigDecimal y1, BigDecimal x2, BigDecimal y2) {
    BigDecimal deltaX = x1.subtract(x2);
    BigDecimal deltaY = y1.subtract(y2);
    this.slope = deltaY.divide(deltaX, SCALE, RoundingMode.CEILING);
    this.yIntercept = y1.subtract(x1.multiply(slope));
}
 
开发者ID:spectrumauctions,项目名称:sats-core,代码行数:7,代码来源:LinearFunction.java

示例14: getLitresFromUsGallon

import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigDecimal getLitresFromUsGallon(BigDecimal value) {
    return value.divide(ONE_LITRE_IS_US_GALLONS, 7, BigDecimal.ROUND_HALF_UP);
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:4,代码来源:VolumeUtil.java

示例15: divide

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 *  Divide numeric object a by object b.
 *
 * @param  a
 * @param  b
 * @param  type
 * @return result
 * @throws  HsqlException
 */
static Object divide(Object a, Object b, int type) throws HsqlException {

    if (a == null || b == null) {
        return null;
    }

    switch (type) {

        case Types.NULL :
            return null;

        case Types.REAL :
        case Types.FLOAT :
        case Types.DOUBLE : {
            double ad = ((Number) a).doubleValue();
            double bd = ((Number) b).doubleValue();

            return ValuePool.getDouble(Double.doubleToLongBits(ad / bd));
        }
        case Types.NUMERIC :
        case Types.DECIMAL : {
            BigDecimal abd   = (BigDecimal) a;
            BigDecimal bbd   = (BigDecimal) b;
            int        scale = abd.scale() > bbd.scale() ? abd.scale()
                                                         : bbd.scale();

            return (bbd.signum() == 0) ? null
                                       : abd.divide(bbd, scale,
                                       BigDecimal.ROUND_DOWN);
        }
        case Types.TINYINT :
        case Types.SMALLINT :
        case Types.INTEGER : {
            int ai = ((Number) a).intValue();
            int bi = ((Number) b).intValue();

            if (bi == 0) {
                throw Trace.error(Trace.DIVISION_BY_ZERO);
            }

            return ValuePool.getInt(ai / bi);
        }
        case Types.BIGINT : {
            long longa = ((Number) a).longValue();
            long longb = ((Number) b).longValue();

            return (longb == 0) ? null
                                : ValuePool.getLong(longa / longb);
        }
        default :
            throw Trace.error(Trace.FUNCTION_NOT_SUPPORTED,
                              Types.getTypeString(type));
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:64,代码来源:Column.java


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