Package com.ibm.icu.math

Examples of com.ibm.icu.math.BigDecimal


    public static Map calcTax(DispatchContext dctx, Map context) {
        Map result = new HashMap();
        List items = (List) context.get("itemProductList");
        List amnts = (List) context.get("itemAmountList");
        List ishpn = (List) context.get("itemShippingList");
        BigDecimal shipping = (BigDecimal) context.get("orderShippingAmount");
        GenericValue address = (GenericValue) context.get("shippingAddress");

        if (items.size() != amnts.size()) {
            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
            result.put(ModelService.ERROR_MESSAGE, "ERROR: Items, Amount, or ItemShipping lists are not valid size.");
            return result;
        }

        try {
            TaxwareUTL utl = new TaxwareUTL();

            utl.setShipping(shipping != null ? shipping : BigDecimal.ZERO);
            utl.setShipAddress(address);
            for (int i = 0; i < items.size(); i++) {
                GenericValue p = (GenericValue) items.get(i);
                BigDecimal amount = (BigDecimal) amnts.get(i);
                BigDecimal ishp = ishpn != null ? (BigDecimal) ishpn.get(i) : BigDecimal.ZERO;

                utl.addItem(p, amount, ishp);
            }

            int resp = utl.process();
View Full Code Here


       
       
        // testing 20 decimal places
        pat = ",##0.00000000000000000001";
        dec = new DecimalFormat(pat);
        BigDecimal bignumber = new BigDecimal("8.888888888888888888885");
        expected = "8.88888888888888888889";
       
        dec.setRoundingMode(BigDecimal.ROUND_HALF_UP);
        str = dec.format(bignumber);
        if (!str.equals(expected)) {
View Full Code Here

        int currentOperationLine = 1;
        // ignore title row
        sc.nextLine();
        currentOperationLine++;

        BigDecimal creditAmount = new BigDecimal(0);
        BigDecimal debitAmount = new BigDecimal(0);

        while (sc.hasNextLine()) {
            Map<String, String> map = new HashMap<String, String>();
            Scanner currentLine = new Scanner(sc.nextLine());
            currentLine.useDelimiter(",");

            String glAccountId = currentLine.next();
            try {
                Integer.parseInt(glAccountId);
                map.put("glAccountId", glAccountId);
            } catch (NumberFormatException ne) {
                String errorMessage = "Balance forward error\nInvalid input at cell A"
                        + currentOperationLine;
                result = ServiceUtil.returnError(errorMessage);
                return result;
            }

            currentLine.next(); // Ignore accountName

            String debit = currentLine.next().toString();

            String credit = "";
            if (debit.equals("") && currentLine.hasNext())
                credit = currentLine.next().toString();

            if (!debit.equals("") && credit.equals("")) {
                try {
                    debitAmount = debitAmount.add(new BigDecimal(debit));
                } catch (NumberFormatException ne) {
                    String errorMessage = "Balance forward error\nInvalid input at cell C"
                            + currentOperationLine;
                    result = ServiceUtil.returnError(errorMessage);
                    return result;
                }
                map.put("amount", debit);
                map.put("debitCreditFlag", "D");
                csvData.add(map);
            } else if (debit.equals("") && !credit.equals("")) {
                try {
                    creditAmount = creditAmount.add(new BigDecimal(credit));
                } catch (NumberFormatException ne) {
                    String errorMessage = "Balance forward error\nInvalid input at cell D"
                            + currentOperationLine;
                    result = ServiceUtil.returnError(errorMessage);
                    return result;
                }
                map.put("amount", credit);
                map.put("debitCreditFlag", "C");
                csvData.add(map);
            }
            currentOperationLine++;
        }

        if (!debitAmount.equals(creditAmount)) {
            String errMsg = "Debit and credit are not equal";
            result = ServiceUtil.returnError(errMsg);
            return result;
        }
View Full Code Here

    {
    }
   
    public void TestBigDecimalFromBigDecimal()
    {
        BigDecimal bigZero = new BigDecimal(0);
       
        try {
            UniversalTimeScale.bigDecimalFrom(bigZero, -1);
            errln("bigDecimalFrom(bigZero, -1) did not throw IllegalArgumentException.");
        } catch (IllegalArgumentException iae) {
View Full Code Here

        }
    }
   
    public void TestToBigDecimalFromBigDecimal()
    {
        BigDecimal bigZero = new BigDecimal(0);
       
        try {
            UniversalTimeScale.toBigDecimal(bigZero, -1);
            errln("toBigDecimal(bigZero, -1) did not throw IllegalArgumentException.");
        } catch (IllegalArgumentException iae) {
View Full Code Here

        }
    }

    public void TestToBigDecimalTrunc()
    {
        BigDecimal bigZero = new BigDecimal(0);
       
        try {
            UniversalTimeScale.toBigDecimalTrunc(bigZero, -1);
            errln("toBigDecimalTrunc(bigZero, -1) did not throw IllegalArgumentException.");
        } catch (IllegalArgumentException iae) {
View Full Code Here

    private long ranMin;
    private long ranMax;
   
    private void initRandom(long min, long max)
    {
        BigDecimal interval = new BigDecimal(max).subtract(new BigDecimal(min));
       
        ranMin = min;
        ranMax = max;
        ranInt = 0;
       
        if (ran == null) {
            ran = createRandom();
        }
       
        if (interval.compareTo(longMax) < 0) {
            ranInt = interval.longValue();
        }
    }
View Full Code Here

     * @param args - the command line arugments
     */
    public static void main(String[] args)
    {
        MessageFormat fmt = new MessageFormat("{0}L, {1}L, {2}L, {3}L");       
        BigDecimal universalMin = new BigDecimal(Long.MIN_VALUE);
        BigDecimal universalMax = new BigDecimal(Long.MAX_VALUE);
        Object limitArgs[] = {null, null, null, null};
       
        System.out.println("\nTo, From limits:");
       
        // from limits
        for(int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) {
            BigDecimal min = UniversalTimeScale.toBigDecimalTrunc(universalMin, scale).max(universalMin);
            BigDecimal max = UniversalTimeScale.toBigDecimalTrunc(universalMax, scale).min(universalMax);
            long minLong   = min.longValue();
            long maxLong   = max.longValue();
           
            limitArgs[2] = min.toString();
            limitArgs[3] = max.toString();

            // to limits
            BigDecimal minTrunc   = UniversalTimeScale.bigDecimalFrom(min, scale);
            BigDecimal maxTrunc   = UniversalTimeScale.bigDecimalFrom(max, scale);
            BigDecimal minResidue = minTrunc.subtract(universalMin);
            BigDecimal maxResidue = universalMax.subtract(maxTrunc);
            long units            = UniversalTimeScale.getTimeScaleValue(scale, UniversalTimeScale.UNITS_VALUE);
            BigDecimal half       = new BigDecimal(units == 1? 0: units / 2 - 1);
           
            min = minTrunc.subtract(minResidue.min(half));
            max = maxTrunc.add(maxResidue.min(half));
            limitArgs[0] = min.toString();
            limitArgs[1] = max.toString();
View Full Code Here

    private StringBuffer format(BigInteger number, StringBuffer result,
            FieldPosition fieldPosition, boolean parseAttr) {
        // If we are to do rounding, we need to move into the BigDecimal
        // domain in order to do divide/multiply correctly.
        if (roundingIncrementICU != null) {
            return format(new BigDecimal(number), result, fieldPosition);
        }

        if (multiplier != 1) {
            number = number.multiply(BigInteger.valueOf(multiplier));
        }
View Full Code Here

                        (Number) new Long(big.longValue()) : (Number) big;
                }
            }
            // Handle non-integral values or the case where parseBigDecimal is set
            else {
                BigDecimal big = digitList.getBigDecimalICU(status[STATUS_POSITIVE]);
                n = big;
                if (mult != 1) {
                    n = big.divide(BigDecimal.valueOf(mult), mathContext);
                }
            }
        }

        // Assemble into CurrencyAmount if necessary
View Full Code Here

TOP

Related Classes of com.ibm.icu.math.BigDecimal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.