0
Getting my percent to always go out to the tenths place. [Java]
Author Summary
pds12345 is
in
Java
Post Body
I am writing a method where I must always have one digit before the decimal and two digits after.
public String getPercentage() throws FractionDenominatorZeroException, LossOfPrecisionException{
int value = 0;
double percent = 0.0;
value = sign*10000*numerator/denominator;
percent = value / 100.0;
return "" percent "%";
}
sign is either 1 or -1 depending on if my fraction is positive or negative. But when doing a calculation like 1/250 I get 0.4 and I need to get 0.40... I am unsure of how I could accomplish this so any help is greatly appreciated! Thank you!
Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
8,864
Link Karma
399
Comment Karma
8,066
Profile updated: 2 days ago
Posts updated: 8 months ago
Subreddit
Post Details
Location
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 10 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnprogra...