I pulled out the penultimate digit of the floating-point number, and to get such a digit, I wrote down the float number into the array via sprintf
, and pulled out the penultimate digit, and translated it through atoi
. But I recorded a two-digit number, so I had to do div 10
. Why atoi took the extra figure on the right, and not translated only one number, but two.
for ( int i = 0; i < N; i++) { x = x + 0.99; memset(myString, 0, 30); t = tan(2.0 * x); sprintf(myString, "%f", t); f_x[i] = atoi(&myString[strlen(myString) - 2])/10; // точность округления 8 знаков и был взят предпоследний //f_x[i] = myString[strlen(myString) - 2]-'0'; еще способ }
atoi
a two-digit entry. And got it. What is an "extra digit to the right"? Why suddenlyatoi
should have considered it "superfluous"? - AnT 4:39 pm