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

x
?
Solved

How do I convert the number 357.99021 to 357.99?

Posted on 2004-11-05
10
Medium Priority
?
248 Views
Last Modified: 2010-03-31
How do I convert the number 357.99021 to 357.99? Thanks.
0
Comment
Question by:jen2483
  • 7
  • 3
10 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 420 total points
ID: 12510301
to display it to 2 places use DecimalFormat:

double d = 357.99021;
DecimalFormat df = new DecimalFormat("0.00");
System.out.println(df.format(d));
0
 
LVL 92

Assisted Solution

by:objects
objects earned 420 total points
ID: 12510306
You can also use BigDecimal class to control the number of decimal places.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 420 total points
ID: 12510308
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 80 total points
ID: 12510319
double d = 357.99021;
BigDecimal bd = new BigDecimal(Double.toString(d)).setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println(bd);
0
 
LVL 92

Expert Comment

by:objects
ID: 12510334
already mentioned, please check comments already posted before posting
0
 
LVL 92

Accepted Solution

by:
objects earned 420 total points
ID: 12510345
or to actually round the value use:

double d = 357.99021;
d = Math.round(d * 100.0) / 100.0; // round to 2 decimal places
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12510352
>>please check comments already posted before posting

I did - there's information missing from the BigDecimal link you posted
0
 
LVL 92

Expert Comment

by:objects
ID: 12510394
> there's information missing from the BigDecimal link you posted

theres nothing missing :-D , it shows how to set the number of decimal places for a big decimal.
Creating the BigDecimal is a no brainer (and you've over complicated it anyway)

BigDecimal bd = new BigDecimal(d);

0
 
LVL 92

Expert Comment

by:objects
ID: 12510425
> I did - there's information missing from the BigDecimal link you posted

Additionally, the page included a link showing how to create and use a BigDecimal (if needed).
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12510545
8-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

580 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