All pastes #189053 Raw Edit

Jim

public java v1 · immutable
·published 2006-10-02 19:36 UTC
rendered paste body
public class DoubleStringer{    public static double StringToDouble(String str)    {        double multiplier = 1.;        if (str.charAt(0) == '-')        {            multiplier = -1.;            str = str.substring(1);        }        if (str.charAt(0) == '+')            str = str.substring(1);        String before, after = "";        int decimal = str.indexOf('.');        if(decimal > -1)        {            before = str.substring(0,decimal);            after = str.substring(decimal+1);        }        else            before = str;        double temp = 0.;        int i;        for(i = before.length(); i > 0; i--)            temp += Integer.parseInt(before.substring(i-1,i)) * Math.pow(10,before.length()-i);        for(i = 0; i < after.length(); i++)            temp += Integer.parseInt(after.substring(i,i+1)) * Math.pow(.1,i+1);        return multiplier * temp;    }}