I am sure this has more to do with my understanding of the behaviour than any inconsistent action on the part of parseFloat, but bear with me...
if I have input in the format "IDCODE: (3.5)" where IDCODE may be a few different predefined strings, and there is guaranteed to always be brackets, and there is also guaranteed to be a number between the brackets
I'm trying to digest all the input into IDCODE buckets and total the values, and therefore need to grab whatever is in between the brackets and turn it into a float so that I can sum it
why does the following not work?
Float tot = 0;
String idCode = "";
while( !input.isEmpty() )
{
idCode = GetIdCode(input);
tot = tot + Float.parseFloat( input.substring(
input.indexOf( "(", input.indexOf( idCode ) ) + 1,
input.indexOf( ")", input.indexOf( idCode ) ) ) );
}
(throws a number format exception)
where the following DOES work
Float tot = 0;
String idCode = "";
while( !input.isEmpty() )
{
idCode = GetIdCode(input);
String temp = input.substring(
input.indexOf( "(", input.indexOf( idCode ) ) + 1,
input.indexOf( ")", input.indexOf( idCode ) ) );
tot = tot + Float.parseFloat( temp );
}
this seems strange to me - what is the difference that I have caused by saving into a temporary variable?