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