|
||
|
||||
|
This code allows you to round a double value to 2 decimal places using DecimalFormat.
You can increase the decimal places by adding an extra #. For example DecimalFormat("#.###"); rounds to 3 decimal places. Java Code
import java.text.*;
public class DecimalPlaces {
public static void main(String[] args) {
double d = 1.234567;
DecimalFormat df = new DecimalFormat("#.##");
System.out.print(df.format(d));
}
}
__________________
Don't forget to add code tags around your code: ![]() Forum Tip: Add to peoples reputation ( ) by clicking the button on their useful posts.
|
![]() |
| Tags |
| decimal places, round number |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] How to Use Decimal Places | napenthia | Java Theory & Questions | 2 | 27-04-2009 08:17 AM |
| How to Type cast convert double to integer | JavaPF | Java Code Snippets and Tutorials | 0 | 07-04-2009 09:52 AM |