PercentageParser { public static float parse(final String value) { final String number = value.substring(0, value.length() - 1); return Float.parseFloat(number); } private  PercentageParser(); static float parse(final String value); static boolean isRelative(final String value);  }
@Test public void testParse() throws Exception { final float rate1 = 97.34f; Assert.assertEquals(rate1, PercentageParser.parse(rate1 + "%"), .001); final float rate2 = 13f; Assert.assertEquals(-rate2, PercentageParser.parse("-" + rate2 + "%"), .001); final float rate3 = 27.2f; Assert.assertEquals(rate3, PercentageParser.parse("+" + rate3 + "%"), .001); }
@Test(expected = NumberFormatException.class) public void testParseNumberFormatException() throws Exception { PercentageParser.parse("rewrw%"); }