Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Reduce % size

Posted on 2011-02-18
Medium Priority
275 Views
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%
0
Question by:gbcbr
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3

LVL 47

Expert Comment

ID: 34927583
I think you should use DecimalFormat like

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

LVL 47

Accepted Solution

for_yan earned 500 total points
ID: 34927660
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

ID: 34927707
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

ID: 34927718
Yes, it is of course also possible
0

LVL 92

Expert Comment

ID: 34929625
0

## Featured Post

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 first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
###### Suggested Courses
Course of the Month9 days, 9 hours left to enroll