Java API for calculating percent -
i'm having troubles finding java api calculate percentages.
eg.
assert theapi.percentofnumber(10.0, 200.0) == 20.0 assert theapi.percentofnumber(25.0, 200.0) == 50.0
i know it's easy calculate, want find api it.
here is
public static double percentofnumber(double x, double y) { return x * 100 / y; }
note, method name longer code have write.
say want calculate percentage of x in 200, can simplify further.
double tenin200 = 10 / 2.0 double twentyfivein200 = 25 / 2.0;
btw answer should be
assert percentofnumber(10.0, 200.0) == 5.0; assert percentofnumber(25.0, 200.0) == 12.5;
Comments
Post a Comment