Here you can find the source of convertInteger(String input, int maxLen)
Parameter | Description |
---|---|
input | a parameter |
maxLen | a parameter |
public static String convertInteger(String input, int maxLen)
//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; } } }