Java Decimal Format getRedondeoHaciaArriba(double pTotal)

Here you can find the source of getRedondeoHaciaArriba(double pTotal)

Description

get Redondeo Hacia Arriba

License

Open Source License

Declaration

public static double getRedondeoHaciaArriba(double pTotal) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double getRedondeoHaciaArriba(double pTotal) {
        if (pTotal > 0.00) {
            String myTotal = formatNumber(pTotal);

            int myRedondeo = Integer.parseInt(myTotal.substring(
                    myTotal.length() - 1, myTotal.length()));

            if (myRedondeo > 5) {
                return (0.01 * (10 - myRedondeo));
            } else if (myRedondeo > 0) {
                return (0.01 * (5 - myRedondeo));
            } else {
                return 0.00;
            }//from  ww w . j  a  v  a 2 s. c  o  m
        } else {
            return 0.00;
        }
    }

    public static String formatNumber(double pValue) {
        java.text.DecimalFormat formatDecimal = new java.text.DecimalFormat(
                ",##0.00");
        java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols();
        symbols.setGroupingSeparator(',');
        symbols.setDecimalSeparator('.');
        formatDecimal.setDecimalFormatSymbols(symbols);
        return formatDecimal.format(pValue).toString();
    }

    public static String formatNumber(double pValue, int pDecimales) {
        java.text.DecimalFormat formatDecimal = new java.text.DecimalFormat(
                ",##0." + caracterIzquierda("", pDecimales, "0"));
        java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols();
        symbols.setGroupingSeparator(',');
        symbols.setDecimalSeparator('.');
        formatDecimal.setDecimalFormatSymbols(symbols);
        return formatDecimal.format(pValue).toString();
    }

    public static String formatNumber(double pValue, String pFormatNumber) {
        java.text.DecimalFormat formatDecimal = new java.text.DecimalFormat(
                pFormatNumber);
        java.text.DecimalFormatSymbols symbols = new java.text.DecimalFormatSymbols();
        symbols.setGroupingSeparator(',');
        symbols.setDecimalSeparator('.');
        formatDecimal.setDecimalFormatSymbols(symbols);
        return formatDecimal.format(pValue).toString();
    }

    public static String caracterIzquierda(int parmint, int parmLen,
            String parmCaracter) {
        return caracterIzquierda(String.valueOf(parmint), parmLen,
                parmCaracter);
    }

    public static String caracterIzquierda(long parmint, int parmLen,
            String parmCaracter) {
        return caracterIzquierda(String.valueOf(parmint), parmLen,
                parmCaracter);
    }

    public static String caracterIzquierda(double parmint, int parmLen,
            String parmCaracter) {
        return caracterIzquierda(String.valueOf(parmint), parmLen,
                parmCaracter);
    }

    public static String caracterIzquierda(String parmString, int parmLen,
            String parmCaracter) {

        String tempString = parmString;

        if (tempString.length() > parmLen)
            tempString = tempString.substring(
                    tempString.length() - parmLen, tempString.length());
        else {
            while (tempString.length() < parmLen)
                tempString = parmCaracter + tempString;
        }

        return tempString;

    }
}

Related

  1. getEngineeringNotation(final double d)
  2. getInteger(Double d)
  3. getIntNum(Double value)
  4. getProgressExact(double balance, double cost)
  5. getRealEye(double eye)
  6. getScientificNotation(double value)
  7. getSpaceMessage(final double bytes)
  8. getStandardDeviationString(double[] standardDeviationDoubles)
  9. getStandardDouble(double d, int pL)