Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to format a double value

Posted on 2005-04-13
6
Medium Priority
?
2,302 Views
Last Modified: 2012-06-22
Hi,

I was wondering whether there is any format function in java like printf in "C" .

 what is the easiest way of formatting a double. I want to have only n numbers after the decimal point.
0
Comment
Question by:sumantedla
  • 2
  • 2
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 1000 total points
ID: 13778990

public String formatToString()
{
   double d = 4.935126;
   NumberFormat formatter = new DecimalFormat("0.0000");
   String s = formatter.format(d);
   return s;
}
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 13779057
java.io.PrintStream.printf(....);     // Exactly what you want.

But, turn to Tiger (JSE5.0); // Reasons enough to do so.

;JOOP!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 24

Expert Comment

by:sciuriware
ID: 13783996
What is wrong with JAVA's .printf() ?

;JOOP!
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 13788080
Nothing :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question