We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,153 Members — Technology Publication meets Social Media

# Logic problem: Percent method

I'm not sure. This the right way to calculate percentage ?
Here's my method

``````public class percent extends Operation {

@Override
public Value calculate(Value key, Value value) {

//BigDecimal result = key.getValue().divide(Value.hundred, Value.SCALE, BigDecimal.ROUND_UP);
return new Value((key.getValue().divide(value.getValue()).multiply(Value.hundred)));
//  return new Value(result);

}

@Override
public String getSymbol() {
return "%";
}

}
``````

**// means doesn't work as well

2
Contributors
2
Replies
36 Minutes
Discussion Span
7 Months Ago
Last Updated
3
Views
Question
enterpise
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Skill Endorsements: 0

My short course of percent calculation:

1. 1 =100% <=> 1% = 0.01
2. Percent calculation does not exist, it is just multiplication.

Everything else follows from these two facts.

pyTony
pyMod
Moderator
6,306 posts since Apr 2010
Reputation Points: 879
Skill Endorsements: 26

Thanks you a lot sir

enterpise
Light Poster
41 posts since Feb 2011
Reputation Points: 10