If your float is already a String then you definitely should go with BigDecimal
. Creating a real intermediate float only add inaccuracy.
String strInteger = new BigDecimal(strFloat).toBigInteger().toString());
Of course you can take advantage of all the arithmetic power of BigDecimal and define a specific rounding mode etc.
EDIT: Just to prove that the float approach will fail (tested in Java 6):
Float.valueOf( "1.99999999" ).intValue()==2
Float.valueOf( "2.9999999" ).intValue()==3
Float.valueOf( "393650.99" ).intValue()==393651
Float.valueOf( "2545818.9" ).intValue()==2545819
(and many more)
Float.valueOf("2.99").intValue() != Math.round(Float.valueOf("2.99"))
You sure you mean rounded integer? \$\endgroup\$