const std::string Money::toString() const { WStringStream ans; if(cents() > 9) ans << value() << "." << cents(); //todo use formater. else ans << value() << ".0" << cents(); //todo use formater. return ans.str(); }
/* * chop the string in two and send the parts away */ void chopandspit(char *str) { int i, dot; char *ip, *fp; for(i=0; i<strlen(str)&&str[i]!='.'; i++); dot=i; ip=(char *)malloc((dot+1)*sizeof(char)); fp=(char *)malloc((strlen(str)-dot+1)*sizeof(char)); for(i=0; i<dot; i++) { ip[i]=str[i]; } ip[i]=0; for(i=dot+1; i<strlen(str)+1; i++) { fp[i-dot-1]=str[i]; } fp[i-dot]=0; dollars(ip); cents(fp); free(fp); free(ip); }
void Money::convert_double(double amount) { zero(); amount += (amount < 0 ? -0.005 : 0.005); cents(int(amount * 100)); }
double Decimal::value() const { return (double)cents() / 100.0; }