Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


Java Tutorials



Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java Beginners RoundTwoDecimalPlaces

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

14 comments so far (post your own) View All Comments Latest 10 Comments:

thank you for the information that this website give about rounding off disimals....because of this i make my score perfect in our exam yesterday....

Posted by marianne kate on Saturday, 08.28.10 @ 05:56am | #99225

public float roundUp(float value) {
DecimalFormat dformat = new DecimalFormat("#.##");
return Float.valueOf(dformat.format(value));

hope it helps.

Posted by kjv007 on Friday, 08.20.10 @ 08:06am | #99060

It's not convention, and is confusing to new programmers.

Method should be camelcased, with a lowercase first letter.


public static float round(...)

Also that method should probably be private, as it isn't need outside the main method.

Posted by Antony Jones on Saturday, 08.14.10 @ 19:14pm | #98920

Why not just:

Math.round(xx*100)/100 if u need to round two decimals? Or 1000 if u need to round 3...?!

Posted by Rasmus on Tuesday, 01.5.10 @ 20:25pm | #93800

Write java program using class name watch and instance variable are hour,minute and second

Posted by Tamirat Adi on Saturday, 12.19.09 @ 22:36pm | #93502

thank you everybody for this program...
you rules!!!

Posted by david on Sunday, 06.28.09 @ 00:53am | #88853

float num = 2.956165f;
DecimalFormat decimal = new DecimalFormat("#.##");
System.out.println("Rounded of decimal::::::::"+decimal.format(num));

Posted by JeenatH on Friday, 06.12.09 @ 12:11pm | #88440

double d = 1.0;
int places = 4;
// See BigDecimal javadoc about why you often want to use the String constructor
double rounded_double = new BigDecimal(d.toString()).setScale(places,BigDecimal.ROUND_HALF_UP).doubleValue();

Posted by Nobody on Friday, 02.27.09 @ 14:58pm | #85303

this round off function is very useful... thanks a lot

Posted by wewee on Sunday, 01.4.09 @ 20:40pm | #83465

You sample helped me quickly. I don't feel like nor have the time to look through the Java API to find out where they've hidden this basic functionality.


Posted by Charles on Friday, 09.5.08 @ 20:47pm | #77277

Nice solution

Posted by Murali on Thursday, 07.3.08 @ 19:11pm | #65533

Why did you create your own rounding off routine when Java has its own rich rounding off scheme (see see the api for class "RoundingMode" at http://java.sun.com/javase/6/docs/api/)

Posted by Bob on Monday, 05.5.08 @ 12:08pm | #58522

It is very easy to understand

Posted by saravanamuthu on Thursday, 06.21.07 @ 11:45am | #19851

Good, Worth reading.

Posted by Rajesh on Thursday, 06.14.07 @ 19:42pm | #19226

Ask programming questions?



Back to Tutorial


  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name


Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.