public static final float parseFloat ( CharSequence cs , int beginIndex , int endIndex ) { FloatState fs = FloatState . Significand ; int end = endIndex ; int significand = 0 ; int sign = 1 ; int index = beginIndex ; int decimal = 0 ; int exponent = 0 ; int exponentSign = 1 ; boolean overFlow = false ; int cp = Character . codePointAt ( cs , index ) ; if ( cp == ' ' ) { index ++ ; } if ( cp == ' ' ) { sign = - 1 ; index ++ ; } if ( index >= end ) { throw new NumberFormatException ( "unparsable number " + cs . subSequence ( beginIndex , endIndex ) ) ; } while ( index < end ) { cp = Character . codePointAt ( cs , index ) ; if ( Character . isBmpCodePoint ( cp ) ) { index ++ ; } else { index += 2 ; } switch ( cp ) { default : int digit = Character . digit ( cp , 10 ) ; if ( digit != - 1 ) { if ( ! overFlow && significand > INT_LIMIT ) { overFlow = true ; } switch ( fs ) { case Significand : if ( ! overFlow ) { significand *= 10 ; significand += digit ; } else { decimal ++ ; } break ; case Decimal : if ( ! overFlow ) { significand *= 10 ; significand += digit ; decimal -- ; } break ; case Exponent : exponent = 10 * exponent + digit ; break ; } } else { throw new NumberFormatException ( "no float " + cs . subSequence ( beginIndex , endIndex ) ) ; } break ; case ' ' : if ( fs != FloatState . Significand ) { throw new NumberFormatException ( "cannot convert " + cs . subSequence ( beginIndex , endIndex ) + " to float" ) ; } fs = FloatState . Decimal ; break ; case ' ' : case ' ' : if ( fs == FloatState . Exponent ) { throw new NumberFormatException ( "cannot convert " + cs . subSequence ( beginIndex , endIndex ) + " to float" ) ; } fs = FloatState . Exponent ; break ; case ' ' : if ( fs != FloatState . Exponent ) { throw new NumberFormatException ( "cannot convert " + cs . subSequence ( beginIndex , endIndex ) + " to float" ) ; } exponentSign = - 1 ; break ; case ' ' : if ( fs != FloatState . Exponent ) { throw new NumberFormatException ( "cannot convert " + cs . subSequence ( beginIndex , endIndex ) + " to float" ) ; } break ; } } return ( float ) ( sign * significand * Math . pow ( 10 , exponentSign * exponent + decimal ) ) ; }
Parses float from decimal floating point representation .