Read a number with commas and decimal dots not using "builtin" support I recently had a job interview and messed up on writing an algorithm which, realistically I wouldn't have any trouble with if I wasn't under pressure. I was annoyed and wrote the solution up when I got home in like 5 minutes. My conclusion as to why this happened: I am a bit rusty at writing algorithms so drawing a blank when pressure is applied, therefore I am practicing several questions to get my mind ticking again. 

I ran into this question;

"Write a program that reads a number with commas and decimal dots (such as “23,419.34”) and then prints a
number that is half of it. Do not use Double.parseDouble()."

Constraints: 


Integer.parseInt only (Assumed) 
No use of Arrays/Lists etc.


Here is my solution;

private static void textToNum() {
    System.out.println("Enter Number nnn,xxx,yyy.zz");
    String text = sc.nextLine();

    double res = 0.0;
    StringBuilder bd = new StringBuilder();

    for (int i = 0; i &lt; text.length(); i++) {
        if (Character.isDigit(text.charAt(i))) {
            System.out.println("CA: " + text.charAt(i));
            bd.append(text.substring(i, i+1));
            if (i == text.length() - 1) {
                double d = Math.pow(10, bd.length());
                double temp = Integer.parseInt(bd.toString()) / d;
                res += (temp / 2);
            }
        }
        else if (text.charAt(i) == '.') {
            res = Integer.parseInt(bd.toString()) / 2.0;
            System.out.println("1Res: " + res);
            bd = new StringBuilder();
        }
    }
    System.out.println("Res: " + res);
}


While this solves the problem, I couldn't help thinking there must be a cleaner solution that I was missing.

Any suggestions?
Was intended as a joke, but should actually work for very large numbers because it only looks at the digits one by one. It uses some knowledge about digit character code points (48..58) O:)

int carry = 0;
boolean dot = false;
for (int i = 0; i &lt; text.length(); i++) {
  char c = text.charAt(i);
  if (c &gt;= '0' &amp;&amp; c &lt;= '9') {
    System.out.print((char) (c / 2 + 24 + carry))
    carry = (c &amp; 1) * 5;
  } else {
    System.out.print(c);
    dot |= c == '.';
  }
}
if (carry != 0) {
  System.out.print(dot ? "5" : ".5");
}


More reasonable (one could do the division inline here, too) -- and no library calls at all (except for printing the result).

double result = 0;
double decimal = 0;
for (int i = 0; i &lt; text.length(); i++) {
  char c = text.charAt(i);
  if (c &gt;= '0' &amp;&amp; c &lt;= '9') {
    if (decimal != 0) {
      result += (c - '0') * decimal;
      decimal /= 10;
    } else {
      result = result * 10 + (c - '0');
    }
  } else if (c == '.') {
    decimal = 0.1;
  }
}
System.out.println(result / 2);