Home Tutorialhelp Allcomments Java Beginners Roundtwodecimalplaces

 
 

Comments

 
User Comments for the tutorial:

Rounding off in Java - Round two decimal places



Advertisement
Comments

Good
Good, Worth reading. 

interesting
It is very easy to understand 

Creation of rounding off scheme?
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/) 

excellent Idea
Nice solution 

Thanks
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. Thanks 

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

BigDecimal approach
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(); 

Not Required to write this much code
float num = 2.956165f; DecimalFormat decimal = new DecimalFormat("#.##"); System.out.println("Rounded of decimal::::::::"+decimal.format(num)); 

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

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

But why?
Why not just: Math.round(xx*100)/100 if u need to round two decimals? Or 1000 if u need to round 3...?! 

Methods should not have capital letters.
It's not convention, and is confusing to new programmers. Method should be camelcased, with a lowercase first letter. namely: public static float round(...) Also that method should probably be private, as it isn't need outside the main me 

another solution
public float roundUp(float value) { DecimalFormat dformat = new DecimalFormat("#.##"); return Float.valueOf(dformat.format(value)); } hope it helps. 

thanks for this website
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.... 

Related Tutorial and Articles
Java Beginners

which data structure is good in java..? - Java Beginners
which data structure is good in java..?  Hi frends, Actually i... and vector ...etc........ i wanted to know, which technique is good to store... anyone give me good example how that best technique i can use in my programs 

Java Beginners

Hi good afternoon
Hi good afternoon  write a java program that Implement an array ADT with following operations: - a. Insert b. Delete c. Number of elements d. Display all elements e. Is Empty 

Java Beginners

HOW TO BECOME A GOOD PROGRAMMER
HOW TO BECOME A GOOD PROGRAMMER  I want to know how to become good programmer   Hi Friend, Please go through the following link... learn java easily and make a command over core java to proceed further. Thanks 

Swing AWT

Good Looking Java Charts and Graphs
Good Looking Java Charts and Graphs  Is there a java chart library that will generate charts and graphs with the quality of visifire or fusion charts? The JFreeChart graph quality is not professional looking. Unless it can 

Java Beginners

mahesh want to know java with good understanding
mahesh want to know java with good understanding  I need to know about java beans(what are java beans,why we use java beans, etc...).I want an example program and it's output also.please teach me...   Java Beans 

Struts Questions

Which is the good website for struts 2 tutorials?
Which is the good website for struts 2 tutorials?  Hi, After completing the MCA I have learned Java and now searching for good tutorial website for learning Struts 2. Suggest met the struts 2 tutorials good websites. Thanks 

Java Beginners

view jsp file (reference file). is the way of coding good ?
view jsp file (reference file). is the way of coding good ?  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> View Retailer <%@ page import="com.tcs.ilp.*" %> 

Java Beginners

Tutorial For Java beginners
Tutorial For Java beginners  I am beginners in Java. Is there any good tutorial and example for beginners in Java? I want to learn Java before Jan... of December 2013. Check the Java Beginners Java Tutorial section for tutorials 

Java Beginners

Java Kick Start - Java Beginners
Java Kick Start  Hello Sir, i like to become a good developer in Java. Im good in JAVA 

Java Beginners

java related - Java Beginners
/ http://www.roseindia.net/java/beginners/ Thanks...java related  Hello sir, I want to learn java. But I don't know where to start from. I have purchased one java related book. But I am 

Advertisements Advertisements
 

 

 

DMCA.com