LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-16-2006, 03:33 PM   #1
linuxmandrake
Member
 
Registered: Sep 2004
Distribution: debian sarge 64bit (AMD)
Posts: 709

Rep: Reputation: 30
rounding a large double to 2 decimal places


How do I do it in java. Am using 1.4.2 and must do
 
Old 03-16-2006, 05:08 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Magic Google 8-Ball said: http://www.codecomments.com/archive2...-8-537423.html
 
Old 03-17-2006, 03:31 PM   #3
Fredstar
Member
 
Registered: Jul 2004
Location: Rochester, NY
Distribution: Fedora9::FreeBSD7.1
Posts: 296

Rep: Reputation: 30
Quote:
Originally Posted by linuxmandrake
How do I do it in java. Am using 1.4.2 and must do
use the DecimalFormat class

DecimalFormat myFormat;
myFormat = new DecimalFormat("0.00") // the 0.00 sets 2 for 2 3 for 3 and so on

then when outputting call it

//if using System.out.println

System.out.println(myformat.Format(2.68546846484));

************************************************
EDIT
************************************************
Sorry rushed in response and thought you were looking to format your output. sorry
which would output 2.68

Last edited by Fredstar; 03-17-2006 at 03:34 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
HEELLP ~~ Converting an integer minute into time, Rounding off a double ~~ HELLP Mistro116@yahoo.com Programming 5 10-04-2005 11:51 AM
C++ Rounding and Truncation Opeth Programming 4 09-17-2005 07:16 PM
how to print 2 decimal places of a double? nadroj Programming 6 07-12-2005 11:03 AM
limit result of float to two decimal places Strus Programming 3 12-17-2004 08:42 PM
Java Precission rounding. Tru_Messiah Programming 4 05-14-2004 11:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration