Here you can find the source of charArrayDecimalToInt(char[] str, int start, int len, int mul)
Parameter | Description |
---|---|
str | a parameter |
start | a parameter |
end | a parameter |
public static int charArrayDecimalToInt(char[] str, int start, int len, int mul)
//package com.java2s; public class Main { /**//from w w w.j av a 2 s .co m * * @param str * @param start * @param end * @return */ public static int charArrayDecimalToInt(char[] str, int start, int len, int mul) { int v = 0; int f = 0; int m = mul; boolean p = false; for (int i = start; i < start + len; i++) { int bit = -1; switch (str[i]) { case '0': bit = 0; break; case '1': bit = 1; break; case '2': bit = 2; break; case '3': bit = 3; break; case '4': bit = 4; break; case '5': bit = 5; break; case '6': bit = 6; break; case '7': bit = 7; break; case '8': bit = 8; break; case '9': bit = 9; break; case '.': if (!p) { p = true; bit = 0; } break; default: break; } if (bit < 0) break; if (p) { f += bit * m; m = m / 10; } else { v += bit; v = v * 10; } } v = v / 10; // println("v="+v+" f="+f); return v * mul + f; } }