C++ (Qt)#include <iostream>#include <math.h>#include <stdio.h>using namespace std; class testClass{private: float var; int acc;public: testClass(float _var = 0.0, int _acc = 0){var = _var; acc = _acc;} void roundVar();}; void testClass::roundVar(){ float temp = var; int i = 0; while(i < acc){ if((temp - floor(temp)) == 0){ cout << i << " : " << temp <<" Number is integer!" << endl; break; } else{ cout << i << " : " << temp - floor(temp) << endl; temp = temp - floor(temp); temp *= 10; i++; } }} int main(){ testClass a(3.14, 2); a.roundVar(); getchar(); return 0;}
0 : 0.141 : 0.400001
C++ (Qt)// temp=3.14// floor(temp) = 3temp = temp - floor(temp);// temp=0.14temp *= 10;// temp=1.4
C++ (Qt)// temp=1.4// floor(temp) = 1temp = temp - floor(temp);// temp=0.4
C++ (Qt)inline qreal MyRound( qreal d, int numDigit, bool truncate = true ){ qreal intP, mul = pow(10.0, (double) numDigit); modf(d * mul + (truncate ? 0.0 : 0.5), &intP); return intP / mul;}