There is a Money class:
class Money { private: unsigned long rouble; unsigned char penny;}; There is a constructor:
Money::Money(const double money) { double intpart; double frac = modf(money, &intpart); if (intpart < 0) { ok = false; } while (frac > 100) { frac--; intpart += 1; } penny = static_cast<unsigned long>(deleteDot(frac)); rouble = static_cast<unsigned long>(intpart); } When transferring it is valid 1.2232, it gives out 1,184. I went through the debugger, but I still did not understand why this is happening.
deleteDot method:
double Money::deleteDot(double &frac) { int x, value = 10; std::stringstream ss; std::string ncbc; //numeral_count_before_comma rouble = (int)frac; ss << frac - (int)frac; //1.12-1=0.12 ncbc = ss.str(); size_t pos = ncbc.find('.'); if (pos != ncbc.npos) { x = ncbc.size() - 1 - pos; } for (int i = 1; i < x; i++) { value *= 10; } frac -= (int)frac; frac *= value; return frac; }