Tuesday, 3 November 2015

How to round double / float value to 2 decimal points in Java

package xyz.jayakumar.test1;

import java.text.DecimalFormat;

public class RoundOf {

public static void main(String[] args)
{
double kilobytes = 1205.6358;

System.out.println("kilobytes : " + kilobytes);

double newKB = Math.round(kilobytes*100.0)/100.0;
System.out.println("kilobytes (Math.round) : " + newKB);

DecimalFormat df = new DecimalFormat("###.##");
System.out.println("kilobytes (DecimalFormat) : " + df.format(kilobytes));
}

}

1 comment:

  1. Best eCOGRA Sportsbook Review & Welcome Bonus 2021 - CA
    Looking for an wooricasinos.info eCOGRA Sportsbook 메이피로출장마사지 Bonus? At this eCOGRA gri-go.com Sportsbook review, we're talking about deccasino a variety of ECCOGRA sportsbook gri-go.com promotions.

    ReplyDelete

Git merge branch to another branch

$ git checkout develop $ git pull $ git checkout test-branch $ git merge develop $ git push