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
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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
Answered
enterpise
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
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
Solved Threads: 986
Skill Endorsements: 26

Thanks you a lot sir

enterpise
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 7 Months Ago by pyTony

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0585 seconds using 2.66MB