Java Integer Convert To convertInteger(String input, int maxLen)

Here you can find the source of convertInteger(String input, int maxLen)

Description

convert Integer

License

Open Source License

Parameter

Parameter Description
input a parameter
maxLen a parameter

Return

String

Declaration

public static String convertInteger(String input, int maxLen) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   www .  j a v  a  2 s  . com*/
     *
     * @param input
     * @param maxLen
     * @return String
     */
    public static String convertInteger(String input, int maxLen) {
        int output = 0;
        int idx = maxLen;
        if (input.length() < maxLen) {
            idx = input.length();
        }
        try {
            output = Integer.parseInt(input.substring(0, idx));
        } catch (Exception e) {
        }
        return Integer.toString(output);
    }

    /**
     *
     * @param strNum
     * @param def
     * @return int
     */

    public static int parseInt(String strNum, int def) {
        if (strNum == null)
            return def;
        if (strNum.indexOf('.') > 0) {
            strNum = strNum.substring(0, strNum.indexOf('.'));
        }
        try {
            return Integer.parseInt(strNum);
        } catch (Exception e) {
            return def;
        }
    }
}

Related

  1. convertIntArray(int[] in)
  2. convertIntArrayFromHex(char[] hex)
  3. convertIntBitsMSBinaryToIEEE(int source)
  4. convertIntColourToByteArray(int intColour)
  5. convertIntDouble(int[][] in)
  6. convertInteger(String str)
  7. convertIntegerArrayToInt(Integer[] integerArray)
  8. convertIntegerToInt(Integer[] values)
  9. convertIntegerToTwoCharString(int integer)