2015年5月19日 星期二

C++ Fixed decimal point

Record how to fix the decimal point in c++
int main(){
 long double o = sqrt(2);
 for(int i = 0 ; i < 20 ; i++){//print long double
        cout.precision(i);
        cout << o << endl;
    }
}
1
1.4
1.41
1.414
1.4142
1.41421
1.414214
1.4142136
1.41421356
1.414213562
1.4142135624
1.41421356237
1.414213562373
1.4142135623731
1.41421356237310
1.414213562373095
1.4142135623730951
1.41421356237309510
1.414213562373095100
1.4142135623730951000

沒有留言:

張貼留言