Comma Formatting for numbers in C++

前端 未结 5 881
北海茫月
北海茫月 2020-12-17 05:30

I\'m needing help in adding commas to the number the user enters, some guidance or help would be appreciated. So far I have it where i store the first three digits and the l

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 06:08

    // Accepts a long number, returns a comma formatted string
    CString num_with_commas(long lnumber)
    {
        CString num;
        num.Format(%d",lnumber);
        if(num.GetLength() > 3) {num.Insert(num.GetLength()-3, ',');}
        if(num.GetLength() > 7) { num.Insert(num.GetLength()-7, ','); }
        if (num.GetLength() > 12) { num.Insert(num.GetLength()-12, ','); }
        return(num);
    }
    

提交回复
热议问题