Example usage for java.math RoundingMode DOWN

List of usage examples for java.math RoundingMode DOWN

Introduction

In this page you can find the example usage for java.math RoundingMode DOWN.

Prototype

RoundingMode DOWN

To view the source code for java.math RoundingMode DOWN.

Click Source Link

Document

Rounding mode to round towards zero.

Usage

From source file:com.nearinfinity.honeycomb.hbase.bulkload.FieldParser.java

private static ByteBuffer extractDecimal(String val, int precision, int right_scale) {
    int left_scale = precision - 2;
    BigDecimal x = new BigDecimal(val);
    boolean is_negative = x.compareTo(BigDecimal.ZERO) == -1;
    x = x.abs();/*w  w w  .  j a v  a2 s.c  o  m*/
    BigDecimal left = x.setScale(0, RoundingMode.DOWN);
    BigDecimal right = x.subtract(left).movePointRight(right_scale);
    int right_bytes_len = bytesFromDigits(right_scale);
    int left_bytes_len = bytesFromDigits(left_scale);
    byte[] left_bytes = left.toBigInteger().toByteArray();
    byte[] right_bytes = right.toBigInteger().toByteArray();
    // Bit twiddling is fun
    byte[] buff = new byte[left_bytes_len + right_bytes_len];

    System.arraycopy(left_bytes, 0, buff, left_bytes_len - left_bytes.length, left_bytes.length);
    System.arraycopy(right_bytes, 0, buff, right_bytes_len - right_bytes.length + left_bytes_len,
            right_bytes.length);

    buff[0] ^= -128; // Flip first bit, 0x80
    if (is_negative) { // Flip all bits
        for (int i = 0; i < buff.length; i++) {
            buff[i] ^= -1; // 0xff
        }
    }
    return ByteBuffer.wrap(buff);
}

From source file:omero.gateway.model.ChannelData.java

/**
 * Returns the label of the channel./*from  w ww  .  ja v  a2  s .  c  o  m*/
 * Following the specification: Name>Fluor>Emission wavelength>index.
 *
 * @return See above.
 */
public String getChannelLabeling() {
    String value = getName();
    if (StringUtils.isNotBlank(value))
        return value;
    value = getFluor();
    if (StringUtils.isNotBlank(value))
        return value;
    Length v = null;
    try {
        v = getEmissionWavelength(null);
    } catch (BigResult e) {
    }
    if (v != null) {
        return "" + DoubleMath.roundToInt(v.getValue(), RoundingMode.DOWN);
    }
    return "" + index;
}

From source file:regresiones.RegresionSimple.java

public void Resolver(JTabbedPane resultados) {

    for (int i = 0; i < 9; i++) {
        sumatorias[i] = 0.0;/*from   ww w.  ja v  a 2  s.  c om*/
    }
    try {
        System.out.println("TOTAL DE DATOS: " + N);
        for (int i = 0; i < N; i++) {
            xiyi[i] = datos[i][0] * datos[i][1];
            System.out.println("X*Y" + i + ": " + xiyi[i]);
            x2[i] = datos[i][0] * datos[i][0]; //elevamos al cuadrado las x's
            y2[i] = datos[i][1] * datos[i][1]; //elevamos al cuadrado las y's
            sumatorias[0] += datos[i][0]; //sumatoria de x
            sumatorias[1] += datos[i][1]; //sumatoria de y

        }
        //sumatoria de xi*yi
        for (int j = 0; j < N; j++) {
            sumatorias[2] += xiyi[j];
        }

        //sumatoria de x^2
        for (int j = 0; j < N; j++) {
            sumatorias[3] += x2[j];
        }

        //sumatoria de y^2
        for (int j = 0; j < N; j++) {
            sumatorias[4] += y2[j];
        }

        mediax = sumatorias[0] / N;
        mediay = sumatorias[1] / N;

        System.out.println("RAIS 25: " + Math.sqrt(25));

        DecimalFormat df = new DecimalFormat("##.##");
        df.setRoundingMode(RoundingMode.DOWN);
        System.out.println("redondeo x^2-- " + df.format(sumatorias[3]));
        System.out.println("redondeo y^2-- " + df.format(sumatorias[4]));
        redondeoSumatoriax2 = Double.parseDouble(df.format(sumatorias[3]));
        redondeoSumatoriay2 = Double.parseDouble(df.format(sumatorias[4]));
        dxy = ((sumatorias[2]) / N) - mediax * mediay;
        dy = Math.sqrt(((redondeoSumatoriay2 / N) - (mediay * mediay)));
        dx = Math.sqrt(((redondeoSumatoriax2 / N) - (mediax * mediax)));

        b1 = ((sumatorias[2] * N) - sumatorias[0] * sumatorias[1])
                / ((sumatorias[3] * N) - (sumatorias[0] * sumatorias[0]));
        b0 = (sumatorias[1] / N) - ((b1 * sumatorias[0]) / N);

        // Y ESTIMADA
        for (int i = 0; i < N; i++) {
            yEstimada[i] = b0 + (b1 * datos[i][0]);
        }

        Se = Math.sqrt((sumatorias[4] - (b0 * sumatorias[1]) - (b1 * sumatorias[2])) / (N - 2));
        r = dxy / (dx * dy);
        System.out.println("sum x: " + sumatorias[0]);
        System.out.println("sum y: " + sumatorias[1]);
        System.out.println("sum x*y: " + sumatorias[2]);
        System.out.println("sum x^2: " + sumatorias[3]);
        System.out.println("sum y^2: " + sumatorias[4]);
        System.out.println("DX7: " + dxy);
        System.out.println("DY: " + dy);
        System.out.println("DX: " + dx);
        System.out.println("B0: " + b0);
        System.out.println("B1: " + b1);

        // mostramos resultados para la pestaa resultados***********************************************************************
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBackground(Color.white);
        JLabel titulo = new JLabel("Resultados");//creamos el titulo
        panel.add(titulo, BorderLayout.PAGE_START);//lo agregamos al inicio
        jtable = new JTable();//creamos la tabla a mostrar
        jtable.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 0), 2, true));
        jtable.setFont(new java.awt.Font("Arial", 1, 14));
        jtable.setColumnSelectionAllowed(true);
        jtable.setCursor(new java.awt.Cursor(java.awt.Cursor.N_RESIZE_CURSOR));
        jtable.setInheritsPopupMenu(true);
        jtable.setMinimumSize(new java.awt.Dimension(80, 80));
        String[] titulos = { "X", "Y", "Xi*Yi", "X2", "Y2", "Y estimada" };//los titulos de la tabla
        arregloFinal = new String[N][6];
        DecimalFormat formato = new DecimalFormat("0.00");
        for (int i = 0; i < N; i++) {//armamos el arreglo
            arregloFinal[i][0] = datos[i][0] + ""; //X
            arregloFinal[i][1] = datos[i][1] + "";//Y
            arregloFinal[i][2] = formato.format(xiyi[i]);
            arregloFinal[i][3] = formato.format(x2[i]);
            arregloFinal[i][4] = formato.format(y2[i]);
            arregloFinal[i][5] = formato.format(yEstimada[i]);
        }
        DefaultTableModel TableModel = new DefaultTableModel(arregloFinal, titulos);
        jtable.setModel(TableModel);
        JScrollPane jScrollPane1 = new JScrollPane();
        jScrollPane1.setViewportView(jtable);
        jtable.getColumnModel().getSelectionModel()
                .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        panel.add(jScrollPane1, BorderLayout.CENTER);
        JPanel panel2 = new JPanel(new GridLayout(0, 4));//creo un panel con rejilla de 4 columnas
        JLabel etiquetaN = new JLabel("N");
        JTextField cajaN = new JTextField();
        cajaN.setText(N + "");
        JLabel etiquetab0 = new JLabel("b0");
        JTextField cajab0 = new JTextField();
        cajab0.setText(b0 + "");
        JLabel etiquetab1 = new JLabel("b1");
        JTextField cajab1 = new JTextField();
        cajab1.setText(b1 + "");
        JLabel etiquetadxy = new JLabel("DXy");
        JTextField cajadxy = new JTextField();
        cajadxy.setText(dxy + "");
        JLabel etiquetadx = new JLabel("DX");
        JTextField cajadx = new JTextField();
        cajadx.setText(dx + "");
        JLabel etiquetady = new JLabel("DY");
        JTextField cajady = new JTextField();
        cajady.setText(dy + "");
        JLabel etiquetaR = new JLabel("R");
        JTextField cajaR = new JTextField();
        cajaR.setText(r + "");
        JLabel etiquetaSE = new JLabel("SE");
        JTextField cajaSE = new JTextField();
        cajaSE.setText(Se + "");
        JButton boton = new JButton("Exportar a PDF");
        boton.addActionListener(this);
        panel2.add(etiquetaN);
        panel2.add(cajaN);
        panel2.add(etiquetab0);
        panel2.add(cajab0);
        panel2.add(etiquetab1);
        panel2.add(cajab1);
        panel2.add(etiquetadxy);
        panel2.add(cajadxy);
        panel2.add(etiquetadx);
        panel2.add(cajadx);
        panel2.add(etiquetady);
        panel2.add(cajady);
        panel2.add(etiquetaR);
        panel2.add(cajaR);
        panel2.add(etiquetaSE);
        panel2.add(cajaSE);
        panel2.add(boton);
        panel.add(panel2, BorderLayout.SOUTH);//agrego el panel2 con rejilla en el panel principal al sur
        resultados.addTab("resultado", panel);
        //**************************************************************************************
        //intervalos de confianza
        JPanel intervalos = new JPanel(new BorderLayout());
        JPanel variables = new JPanel(new GridLayout(0, 2));
        JLabel variableX1 = new JLabel("X1");
        cajaVariableX1 = new JTextField();
        boton = new JButton("calcular");
        boton.addActionListener(this);
        JLabel variableEfectividad = new JLabel("Efectividad");
        String[] efectividades = { "80", "85", "90", "95", "99" };
        combo = new JComboBox(efectividades);
        variables.add(variableX1);
        variables.add(cajaVariableX1);
        variables.add(variableEfectividad);
        variables.add(combo);
        variables.add(boton);//comentario
        //cometario2
        intervalos.add(variables, BorderLayout.NORTH);
        jtable2 = new JTable();//creamos la tabla a mostrar
        jtable2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 0), 2, true));
        jtable2.setFont(new java.awt.Font("Arial", 1, 14));
        jtable2.setColumnSelectionAllowed(true);
        jtable2.setCursor(new java.awt.Cursor(java.awt.Cursor.N_RESIZE_CURSOR));
        jtable2.setInheritsPopupMenu(true);
        jtable2.setMinimumSize(new java.awt.Dimension(80, 80));
        String[] titulos2 = { "Y estimada", "Li", "Ls" };//los titulos de la tabla
        String[][] pruebaIntervalos = { { "", "", "" } };
        DefaultTableModel TableModel2 = new DefaultTableModel(pruebaIntervalos, titulos2);
        jtable2.setModel(TableModel2);
        JScrollPane jScrollPane2 = new JScrollPane();
        jScrollPane2.setViewportView(jtable2);
        jtable2.getColumnModel().getSelectionModel()
                .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        intervalos.add(jScrollPane2, BorderLayout.CENTER);
        resultados.addTab("intervalos", intervalos);
        // ***********************************************************************
        JPanel graficas = new JPanel(new GridLayout(0, 1));
        XYDataset dataset = createSampleDataset();
        JFreeChart chart = ChartFactory.createXYLineChart("Grafica", "X", "Y", dataset,
                PlotOrientation.VERTICAL, true, false, false);
        XYPlot plot = (XYPlot) chart.getPlot();
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(0, true);
        renderer.setSeriesShapesVisible(0, true);
        renderer.setSeriesLinesVisible(1, true);
        renderer.setSeriesShapesVisible(1, true);
        plot.setRenderer(renderer);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
        graficas.add(chartPanel);//agregamos la primer grafica
        resultados.addTab("Graficas", graficas);
        //IMPRIMIR JTABLE
        /* MessageFormat headerFormat = new MessageFormat("MI CABECERA");
         MessageFormat footerFormat = new MessageFormat("- Pgina {0} -");
         jtable.print(PrintMode.FIT_WIDTH, headerFormat, footerFormat);
         */

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.trend.hgraph.VariousTest.java

@Test
public void testBigDecimalCompare() {
    BigDecimal a = null;/*ww w  .ja  va2  s  .  c o m*/
    BigDecimal b = null;

    System.out.println("***test scale");
    a = new BigDecimal("2.12345");
    System.out.println(a.scale());

    a = new BigDecimal("200.12345");
    System.out.println(a.scale());

    a = new BigDecimal("200.12");
    System.out.println(a.scale());

    a = new BigDecimal("200.12345");
    System.out.println(a);
    a = a.setScale(2, RoundingMode.DOWN);
    System.out.println(a);
    System.out.println(a.scale());

    System.out.println("***test compare #1");
    a = new BigDecimal("500.123456");
    b = new BigDecimal("500.126543");

    System.out.println("a=" + a);
    System.out.println("b=" + b);
    System.out.println("a comapre b =>" + a.compareTo(b));

    a = a.setScale(2, RoundingMode.DOWN);
    b = b.setScale(2, RoundingMode.DOWN);

    System.out.println("a=" + a);
    System.out.println("b=" + b);
    System.out.println("a comapre b =>" + a.compareTo(b));

    System.out.println("***test compare #2");
    a = new BigDecimal("500.1");
    b = new BigDecimal("500.126543");

    System.out.println("a=" + a);
    System.out.println("b=" + b);
    System.out.println("a comapre b =>" + a.compareTo(b));

    a = a.setScale(3, RoundingMode.DOWN);
    b = b.setScale(3, RoundingMode.DOWN);

    System.out.println("a=" + a);
    System.out.println("b=" + b);
    System.out.println("a comapre b =>" + a.compareTo(b));
}

From source file:org.goko.core.rs274ngcv3.RS274.java

public static BigDecimal buildBigDecimal(String value) throws GkException {
    BigDecimal bigDecimal = new BigDecimal(value);
    if (RS274Preference.getInstance().isDecimalTruncateEnabled()) {
        int decimalCount = RS274Preference.getInstance().getDecimalCount();
        if (bigDecimal.scale() > decimalCount) {
            bigDecimal = bigDecimal.setScale(decimalCount, RoundingMode.DOWN);
        }/*from   w w  w .j av  a2s.c o m*/
    }
    return bigDecimal;
}

From source file:org.libreplan.business.orders.daos.OrderElementDAO.java

@Override
@Transactional(readOnly = true)/*from  w  ww  . j a  v a2 s  .  c  o m*/
public BigDecimal getHoursAdvancePercentage(OrderElement orderElement) {
    boolean condition = orderElement.getSumChargedEffort() != null;

    final EffortDuration totalChargedEffort = condition
            ? orderElement.getSumChargedEffort().getTotalChargedEffort()
            : EffortDuration.zero();

    BigDecimal assignedHours = totalChargedEffort.toHoursAsDecimalWithScale(2);
    BigDecimal estimatedHours = new BigDecimal(orderElement.getWorkHours()).setScale(2);

    return estimatedHours.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO
            : assignedHours.divide(estimatedHours, RoundingMode.DOWN);
}

From source file:edu.synth.state.SyntHelperState.java

public void handleObsData() throws IOException {
    File obsFile = new File(Constants.OBS_DATA);
    TreeMap<Double, Double> obs = FileWorker.getSortedDoubleData(obsFile);

    synthSettings.setStartSynth(new BigDecimal(obs.firstKey()).setScale(0, RoundingMode.DOWN).intValue());
    synthSettings.setEndSynth(new BigDecimal(obs.lastKey()).setScale(0, RoundingMode.UP).intValue());

    List<String> strs = new ArrayList<String>();
    for (Entry<Double, Double> ent : obs.entrySet())
        strs.add(String.format(Locale.ENGLISH, "%1.4f %1.4f", ent.getKey(), ent.getValue()));
    FileWorker.write(obsFile, strs);//w w  w  .  j  a va2  s . c  om
}

From source file:eu.uqasar.util.UQasarUtil.java

/**
 * Round double to two decimals//from www  .ja  va 2 s . c o m
 * @param number
 * @return
 */
public static Double round(double number) {
    DecimalFormat df = new DecimalFormat("#,##");
    df.setRoundingMode(RoundingMode.DOWN);
    String s = df.format(number);
    return Double.valueOf(s);
}

From source file:org.libreplan.ws.common.impl.OrderElementConverter.java

public static final AdvanceMeasurementDTO toDTO(BigDecimal maxValue, boolean isPercentage,
        AdvanceMeasurement advanceMeasurement) {

    BigDecimal value;/*from w w w .ja v a 2  s. c  o  m*/
    if (isPercentage) {
        value = advanceMeasurement.getValue();
    } else {
        value = advanceMeasurement.getValue().divide(maxValue, RoundingMode.DOWN);
    }

    return new AdvanceMeasurementDTO(DateConverter.toXMLGregorianCalendar(advanceMeasurement.getDate()), value);
}

From source file:com.dp2345.entity.Cart.java

/**
 * ?/*from  w w w  .  j av  a2  s  . c  o m*/
 * 
 * @return 
 */
@Transient
public BigDecimal getDiscount() {
    BigDecimal originalPrice = new BigDecimal(0);
    BigDecimal currentPrice = new BigDecimal(0);
    for (Promotion promotion : getPromotions()) {
        if (promotion != null) {
            int promotionQuantity = getQuantity(promotion);
            BigDecimal originalPromotionPrice = getTempPrice(promotion);
            BigDecimal currentPromotionPrice = promotion.calculatePrice(promotionQuantity,
                    originalPromotionPrice);
            originalPrice = originalPrice.add(originalPromotionPrice);
            currentPrice = currentPrice.add(currentPromotionPrice);
            Set<CartItem> cartItems = getCartItems(promotion);
            for (CartItem cartItem : cartItems) {
                if (cartItem != null && cartItem.getTempPrice() != null) {
                    BigDecimal tempPrice;
                    if (originalPromotionPrice.compareTo(new BigDecimal(0)) > 0) {
                        tempPrice = currentPromotionPrice.divide(originalPromotionPrice, 50, RoundingMode.DOWN)
                                .multiply(cartItem.getTempPrice());
                    } else {
                        tempPrice = new BigDecimal(0);
                    }
                    cartItem.setTempPrice(
                            tempPrice.compareTo(new BigDecimal(0)) > 0 ? tempPrice : new BigDecimal(0));
                }
            }
        }
    }
    if (getCartItems() != null) {
        for (CartItem cartItem : getCartItems()) {
            if (cartItem != null) {
                cartItem.setTempPrice(null);
            }
        }
    }
    Setting setting = SettingUtils.get();
    BigDecimal discount = setting.setScale(originalPrice.subtract(currentPrice));
    return discount.compareTo(new BigDecimal(0)) > 0 ? discount : new BigDecimal(0);
}