# How To Round Double To One Decimal Place

Page 1 of 1

## 2 Replies - 118561 Views - Last Post: 30 April 2008 - 05:12 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=8205&amp;s=17ae3acf3fefcd8d86f26d0b2138ca1f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Java Boy

Reputation: 0
• Posts: 1
• Joined: 20-September 03

# How To Round Double To One Decimal Place

Posted 20 September 2003 - 11:13 PM

hello! I am new to Java, so I hope some of you experts here can help me out.
here is my source code
```//********************************************************************************************
//
//a Java program that prompts a CPSC 111 student for their grades in the course and their
//projected final exam grade and then computes their overall grade for the course.
//********************************************************************************************

import java.io.*;
import java.text.NumberFormat;

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

String name;

System.out.println ();

System.out.print ("enter average grade on labs: ");

System.out.print ("enter average grade on assignments: ");

System.out.print ("enter projected grade on midterms: ");

System.out.print ("enter average grade on final exam: ");

System.out.println (name + ", your overall grade for CPSC 111 is " + totalGrade + " %!");
}
}

```

I would like to print out my result of totalGrade to ONE decimal place one. Can anyone tell me which methods to use? Thanx!

Is This A Good Question/Topic? 0

## Replies To: How To Round Double To One Decimal Place

### #2 megamu

• Information Designer

Reputation: 0
• Posts: 1,829
• Joined: 13-May 01

## Re: How To Round Double To One Decimal Place

Posted 23 September 2003 - 12:32 PM

double rounded = int(number*10)/10;

### #14 C:/Syntax

Reputation: 4
• Posts: 35
• Joined: 12-April 08

## Re: How To Round Double To One Decimal Place

Posted 30 April 2008 - 05:12 PM

```import java.io.*;
import java.text.*; //need for DecimalFormat class
public class PayRoll12{
public static void main (String [] args){
DecimalFormat twoDigit = new DecimalFormat("#,##0.000");//formats to 3 decimal places
DecimalFormat twoDigit = new DecimalFormat("#,##0.00");//formats to 2 decimal places
DecimalFormat oneDigit = new DecimalFormat("#,##0.0");//format to 1 decimal place
/**
*can format to any decimal place, just by editting the "zeros"("#,##0.000"),
*and changing to a meaningful varible name(threeDigit)
*/

System.out.println(twoDigit.format(anyVariable));
System.out.println(oneDigit.format(anyVariable));

}
}
```

I like this much better then the upper post