Example usage for java.math BigDecimal movePointLeft

List of usage examples for java.math BigDecimal movePointLeft

Introduction

In this page you can find the example usage for java.math BigDecimal movePointLeft.

Prototype

public BigDecimal movePointLeft(int n) 

Source Link

Document

Returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left.

Usage

From source file:org.kalypso.model.wspm.pdb.internal.wspm.CrossSectionConverter.java

@Override
public IStatus execute(final IProfile profile) {
    m_profile.setName(m_section.getName());
    m_profile.setDescription(m_section.getDescription());

    /* [m] -> [km] */
    final BigDecimal station = m_section.getStation();
    m_profile.setStation(station.movePointLeft(3).doubleValue());

    convertP();//from www  . j  av  a  2s.co  m
    convertParts();

    return Status.OK_STATUS;
}

From source file:com.heliumv.api.inventory.InventoryApi.java

private boolean isDifferenceToLarge(BigDecimal baseAmount, BigDecimal newAmount) {
    BigDecimal percentAllowed = new BigDecimal(10);
    BigDecimal amplitude = baseAmount.movePointLeft(2).multiply(percentAllowed);
    if (amplitude.compareTo(BigDecimal.ONE) <= 0) {
        amplitude = BigDecimal.ONE;
    }/*from www. j  ava2 s.co m*/
    return baseAmount.subtract(newAmount).abs().compareTo(amplitude) > 0;
}

From source file:org.kuali.kfs.module.purap.service.impl.PurapAccountingServiceImpl.java

/**
 * gets the lowest possible number for rounding, it works for ROUND_HALF_UP
 *
 * @return a BigDecimal representing the lowest possible number for rounding
 *///from  ww w. j a  v a  2 s .c  o  m
protected BigDecimal getLowestPossibleRoundUpNumber() {
    BigDecimal startingDigit = new BigDecimal(0.5);
    if (SCALE != 0) {
        startingDigit = startingDigit.movePointLeft(SCALE);
    }
    return startingDigit;
}

From source file:com.lp.server.artikel.fastlanereader.ArtikellisteHandler.java

protected void prepareVkPreis(HashMap hmRabattsatzFixpreis, HashMap hmPreisbasis, Object[] source,
        Object[] target) {//  ww  w .  ja va2 s .  co m
    // VK-Preis Berechnen
    BigDecimal vkPreis = null;

    BigDecimal vkPreisbasis = new BigDecimal(0);
    BigDecimal vkRabattsatz = new BigDecimal(0);
    BigDecimal vkFixpreis = new BigDecimal(0);

    if (hmRabattsatzFixpreis.containsKey(source[0])) {
        Object[] oTemp = (Object[]) hmRabattsatzFixpreis.get(source[0]);
        vkRabattsatz = (BigDecimal) oTemp[1];
        vkFixpreis = (BigDecimal) oTemp[2];
    }
    if (hmPreisbasis.containsKey(source[0])) {
        vkPreisbasis = (BigDecimal) hmPreisbasis.get(source[0]);
    }

    if (vkFixpreis != null) {
        vkPreis = vkFixpreis;
    } else {
        if (vkRabattsatz != null && vkPreisbasis != null) {
            BigDecimal bdRabattsumme = vkPreisbasis.multiply(vkRabattsatz.movePointLeft(2));
            vkPreis = vkPreisbasis.subtract(bdRabattsumme);
        } else {
            vkPreis = vkPreisbasis;
        }
    }
    target[getTableColumnInformation().getViewIndex("lp.preis")] = vkPreis;
}

From source file:org.multibit.utils.CSMiscUtils.java

public static BigDecimal getDisplayUnitsForRawUnits(CSAsset asset, BigInteger rawQuantity) {
    if (asset == null)
        return BigDecimal.ZERO;
    CoinSparkGenesis genesis = asset.getGenesis();
    if (genesis == null)
        return BigDecimal.ZERO; // This can happen with brand new Manually transferred asset which has not yet been validated.
    int chargeBasisPoints = genesis.getChargeBasisPoints();
    int chargeExponent = genesis.getChargeFlatExponent();
    int chargeMantissa = genesis.getChargeFlatMantissa();
    int qtyExponent = genesis.getQtyExponent();
    int qtyMantissa = genesis.getQtyMantissa();

    double interestRate = asset.getInterestRate();
    Date issueDate = asset.getIssueDate();

    BigDecimal result = new BigDecimal(rawQuantity.toString());

    //System.out.println("interest rate = " + interestRate);
    //System.out.println("issue date = " + issueDate);

    //System.out.println("raw units =" + result);

    // 1. Compute interest
    if (issueDate != null && interestRate != 0.0) {

        BigDecimal rate = new BigDecimal(String.valueOf(interestRate));
        rate = rate.divide(new BigDecimal(100));
        rate = rate.add(BigDecimal.ONE);
        //interestRate = interestRate / 100;

        //System.out.println("interest rate 1 + ir/100 = " + rate.toPlainString());

        // get years elapsed
        DateTime d1 = new DateTime(issueDate);
        DateTime d2 = new DateTime();

        //System.out.println("Issue: " + d1 + "   Now: " + d2);
        int seconds = Math.abs(Seconds.secondsBetween(d1, d2).getSeconds());

        //System.out.println("...Number of seconds difference: " + seconds);

        BigDecimal elapsedSeconds = new BigDecimal(seconds);

        //System.out.println("...Number of seconds difference: " + elapsedSeconds.toPlainString());

        // To avoid exception, we need to set a precision.
        // java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
        // http://stackoverflow.com/questions/4591206/arithmeticexception-non-terminating-decimal-expansion-no-exact-representable
        BigDecimal elapsedYears = elapsedSeconds.divide(new BigDecimal(COINSPARK_SECONDS_IN_YEAR),
                MathContext.DECIMAL32);
        //System.out.println("...Number of years difference: " + elapsedYears.toPlainString());

        double base = elapsedSeconds.doubleValue();
        double exp = elapsedYears.doubleValue();
        //System.out.println("...base=" + base + "  exponent=" + exp);
        double interestMultipler = Math.pow(rate.doubleValue(), elapsedYears.doubleValue());

        //System.out.println("interest multipler =" + interestMultipler);

        result = result.multiply(new BigDecimal(interestMultipler));

        //System.out.println("raw units with interest multiplier =" + result);

        result = result.setScale(0, RoundingMode.DOWN);

        //System.out.println("raw units with interest multiplier, floored =" + result);

    }//from  w  w  w.jav a 2 s .  c om

    // 2. Apply multiple
    int decimalPlaces = CSMiscUtils.getNumberOfDisplayDecimalPlaces(asset);
    BigDecimal display = result;
    if (decimalPlaces != 0) {
        //       System.out.println(">>>>> display = " + display.toPlainString());
        display = result.movePointLeft(decimalPlaces);
        //       System.out.println(">>>>> display = " + display.toPlainString());
    }

    //long qty = Utils.mantissaExponentToQty(qtyMantissa, qtyExponent);
    //   double multiple = asset.getMultiple();
    // let's just do it for now to make sure code is corret   
    //if (multiple != 1.0)
    //   BigDecimal m = new BigDecimal(String.valueOf(multiple));
    //   BigDecimal display = result.multiply(m);

    //System.out.println("multiplier=" + m + ", display=" + display);
    // Stripping zeros from internal zero with different scale does not work, so use 
    // JDK bug still seems to exist
    // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6480539
    // http://stackoverflow.com/questions/5239137/clarification-on-behavior-of-bigdecimal-striptrailingzeroes
    int cmpZeroResult = display.compareTo(BigDecimal.ZERO);
    if (decimalPlaces == 0) {
        display = display.stripTrailingZeros();
    }

    // Stripping trailing zeros from internal zero with different scale does not work, so set to ZERO instead.
    if (0 == cmpZeroResult) {
        display = BigDecimal.ZERO;
    }
    return display;
}