public static Number parseDecimal ( String text ) { text = text . replace ( "_" , "" ) ; int length = text . length ( ) ; // // Strip off any type specifier and convert it to lower // case, if present. char type = ' ' ; if ( isNumericTypeSpecifier ( text . charAt ( length - 1 ) , true ) ) { type = Character . toLowerCase ( text . charAt ( length - 1 ) ) ; text = text . substring ( 0 , length - 1 ) ; } // // Build the specified type or default to BigDecimal BigDecimal value = new BigDecimal ( text ) ; switch ( type ) { case ' ' : if ( value . compareTo ( MAX_FLOAT ) <= 0 && value . compareTo ( MIN_FLOAT ) >= 0 ) { return Float . parseFloat ( text ) ; } throw new NumberFormatException ( "out of range" ) ; case ' ' : if ( value . compareTo ( MAX_DOUBLE ) <= 0 && value . compareTo ( MIN_DOUBLE ) >= 0 ) { return Double . parseDouble ( text ) ; } throw new NumberFormatException ( "out of range" ) ; case ' ' : default : return value ; } }
Builds a Number from the given decimal descriptor . Uses BigDecimal unless Double or Float is requested .