Example usage for java.math RoundingMode CEILING

List of usage examples for java.math RoundingMode CEILING

Introduction

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

Prototype

RoundingMode CEILING

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

Click Source Link

Document

Rounding mode to round towards positive infinity.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DecimalFormat format = new DecimalFormat();
    format.setRoundingMode(RoundingMode.CEILING);
    System.out.println(format.format(123456789123.45678));

}

From source file:NumberFormatRounding.java

public static void main(String[] args) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(2);//  w  ww.  j a v a2s  .  c  o m
    nf.setRoundingMode(RoundingMode.CEILING);
    System.out.println("Default rounding mode: " + nf.getRoundingMode());
    System.out.println("123.454 rounds to " + nf.format(123.454));
    System.out.println("123.455 rounds to " + nf.format(123.455));
    System.out.println("123.456 rounds to " + nf.format(123.456));
    System.out.println();

}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("16");
    BigDecimal bg2 = new BigDecimal("3");

    // divide bg1 with bg2 with 3 scale
    BigDecimal bg3 = bg1.divide(bg2, 3, RoundingMode.CEILING);

    System.out.println(bg3);/*from  w  w  w  . j  a v a  2 s  . c om*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    numberFormat.setCurrency(Currency.getInstance(Locale.CANADA));
    numberFormat.setRoundingMode(RoundingMode.CEILING);

}

From source file:NumberFormatRounding.java

public static void main(String[] args) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(2);//w  w w .  j a va2s  .  com
    nf.setRoundingMode(RoundingMode.HALF_DOWN);
    System.out.println("Default rounding mode: " + nf.getRoundingMode());
    System.out.println("123.454 rounds to " + nf.format(123.454));
    System.out.println("123.455 rounds to " + nf.format(123.455));
    System.out.println("123.456 rounds to " + nf.format(123.456));
    System.out.println();

    nf.setRoundingMode(RoundingMode.FLOOR);
    System.out.println("Default rounding mode: " + nf.getRoundingMode());
    System.out.println("123.454 rounds to " + nf.format(123.454));
    System.out.println("123.455 rounds to " + nf.format(123.455));
    System.out.println("123.456 rounds to " + nf.format(123.456));
    System.out.println();

    nf.setMaximumFractionDigits(2);
    nf.setRoundingMode(RoundingMode.CEILING);
    System.out.println("Default rounding mode: " + nf.getRoundingMode());
    System.out.println("123.454 rounds to " + nf.format(123.454));
    System.out.println("123.455 rounds to " + nf.format(123.455));
    System.out.println("123.456 rounds to " + nf.format(123.456));
    System.out.println();

}

From source file:com.enitalk.controllers.paypal.Usd.java

public static void main(String[] args) throws IOException, ParseException {

    String rs = Request.Get("http://www.cbr.ru/scripts/XML_daily.asp")
            .addHeader("Content-type", "application/xml;charset=utf-8").execute().returnContent()
            .asString(Charset.forName("windows-1251"));

    Pair<AutoPilot, VTDNav> bb = getNavigator(rs.getBytes());
    String change = getChange(bb.getLeft(), bb.getRight());

    System.out.println("Rs " + change);
    DecimalFormat df = new DecimalFormat();
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setDecimalSeparator(',');
    df.setDecimalFormatSymbols(symbols);
    BigDecimal dd = BigDecimal.valueOf(df.parse(change).doubleValue()).setScale(2, RoundingMode.CEILING);
    System.out.println("Dd " + dd);
}

From source file:Main.java

public static String formatByte(long l) {
    String s = "0 KB";
    if (l <= 0x100000L) {
        BigDecimal bigdecimal = new BigDecimal(l);
        BigDecimal bigdecimal1 = new BigDecimal(1024);
        RoundingMode roundingmode = RoundingMode.CEILING;
        String s1 = String.valueOf(bigdecimal.divide(bigdecimal1, 0, roundingmode).toString());
        s = (new StringBuilder(s1)).append(" KB").toString();
    } else {/*from  ww w.  j ava  2 s.com*/
        if (l >= 0x40000000L) {
            BigDecimal bigdecimal2 = new BigDecimal(l);
            BigDecimal bigdecimal3 = new BigDecimal(0x40000000);
            RoundingMode roundingmode1 = RoundingMode.CEILING;
            String s2 = String.valueOf(bigdecimal2.divide(bigdecimal3, 2, roundingmode1).toString());
            s = (new StringBuilder(s2)).append(" G").toString();
        } else {
            BigDecimal bigdecimal4 = new BigDecimal(l);
            BigDecimal bigdecimal5 = new BigDecimal(0x100000);
            RoundingMode roundingmode2 = RoundingMode.CEILING;
            String s3 = String.valueOf(bigdecimal4.divide(bigdecimal5, 2, roundingmode2).toString());
            s = (new StringBuilder(s3)).append(" MB").toString();
        }
    }
    return s;
}

From source file:Main.java

/**
 * Rounds a double up via passed in amount and places
 * @param value/*w w w.j  a  v  a  2  s.  c o m*/
 * @param places
 * @return
 */
public static double roundUp(double value, int places) {
    if (places < 0)
        throw new IllegalArgumentException();

    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(places, RoundingMode.CEILING);
    return bd.doubleValue();
}

From source file:com.shenit.commons.utils.Formatter.java

/**
 * ?/*from  w  w  w . jav  a2  s .co m*/
 * @param num 
 * @param scale ????
 * @return
 */
public static String formatPrice(double num) {
    return new BigDecimal(num).setScale(2, RoundingMode.CEILING).toPlainString();
}

From source file:GeMSE.GS.Analysis.Stats.TwoSampleCovariancePanel.java

public TwoSampleCovariancePanel() {
    initComponents();//from   www.  java2 s .c  o  m

    _decFor = new DecimalFormat("#.#########");
    _decFor.setRoundingMode(RoundingMode.CEILING);
    DecimalFormatSymbols decFors = _decFor.getDecimalFormatSymbols();
    decFors.setNaN("NaN");
    decFors.setInfinity("");
    _decFor.setDecimalFormatSymbols(decFors);

    _biasCorrected = false;
    BiasCorrectedCB.setSelected(_biasCorrected);
}