Assume there is a class Shape. The class has two functions area() and perimeter().
Let's say Circle and Square inherit from Shape and override these methods. Obviously the results are going to be fractional.
What is the best way to set a precision value for the results. Say the user says PRECISION=2 or PRECISION=3 and the results returned by the functions of Circle and Square class are returned accordingly. Where should I define this functionality? I was wondering how do libraries like numpy handle this situation.
One approach can be to add an optional parameter to these functions and round the results accordingly.
getArea(radius, prec=2) {
}