Solved

Reduce % size

Posted on 2011-02-18
5
269 Views
Last Modified: 2012-05-11
Please advise how to make correct percentage view with only 2 digits after comma.
now I have:
System.out.println("    Margin use = " + (u / c * 100) + "%")
.............
output

 Margin use = 1.5060808012349864%

Open in new window

0
Comment
Question by:gbcbr
  • 3
5 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
I think you should use DecimalFormat like

http://www.roseindia.net/java/beginners/DecimalFormatExample.shtml
0
 
LVL 47

Accepted Solution

by:
for_yan earned 125 total points
Comment Utility
so if you have it like that:

    double amount = (u / c * 100);
    NumberFormat formatter = new DecimalFormat("#0.00");
System.out.println  ("Margin Use = " + formatter.format(amount) + "%")

     
0
 

Author Comment

by:gbcbr
Comment Utility
Thank you, I make it even easy
        NumberFormat formatter = new DecimalFormat("#0.00");
        System.out.println("    Margin use = " + formatter.format(u / c * 100) + "%");
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Yes, it is of course also possible
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now