string doubleToString(const double &dbNum){char *chCode;chCode = new(std::nothrow)char[20];sprintf(chCode, "%.2lf", dbNum); // .2 是控制输出精度的,两位小数string strCode(chCode);delete []chCode;return strCode;}//调用方式double dboule = 100.01555;string str = doubleToString(dboule);cout << str << endl;
