2013年7月15日 星期一

servlet roundup numeric

java servlnet roundup

e.g. double result=round(1234.567890123,5);  // = 1234.56789

static double round(double _d,int _i){
    double r=0;
    switch (_i)
    {
        case 1: r=Math.round(_d*10)/10.0; break;
        case 2: r=Math.round(_d*100)/100.00; break;
        case 3: r=Math.round(_d*1000)/1000.000; break;
        case 4: r=Math.round(_d*10000)/10000.0000; break;
        case 5: r=Math.round(_d*100000)/100000.00000; break;
        case 6: r=Math.round(_d*1000000)/1000000.000000; break;
        default : r=Math.round(_d);
    }
    return r;
}

沒有留言:

張貼留言