달력

52024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
반응형
        private string AddComma(double dblTemp)
        {
            string strTemp = dblTemp.ToString();

            string strDotUnderGrp = string.Empty;
            string strDotUpGrp = string.Empty;

            if (strTemp.IndexOf('.') > -1)
            {
                strDotUnderGrp = strTemp.Substring(strTemp.IndexOf('.'));
                strDotUpGrp = strTemp.Substring(0, strTemp.IndexOf('.'));
            }
            else
                strDotUpGrp = strTemp;

            if (strDotUpGrp == string.Empty) strDotUpGrp = "0";

            char[] chrDotUpGrpR = strDotUpGrp.ToCharArray();
            Array.Reverse(chrDotUpGrpR);
            string strDotUpGrpR = new string(chrDotUpGrpR);

            int arrCnt = (strDotUpGrpR.Length / 3) + (strDotUpGrpR.Length % 3 > 0 ? 1 : 0);

            string[] strArr = new string[arrCnt];

            for (int i = 0; i < arrCnt; i++)
            {
                if (arrCnt - 1 == i)
                {
                    strArr[i] = strDotUpGrpR.Substring(i * 3);
                    break;
                }
                else
                    strArr[i] = strDotUpGrpR.Substring((i * 3), 3);
            }

            string strArrR = string.Join(",", strArr);

            char[] chrDotUpGrp = strArrR.ToCharArray();
            Array.Reverse(chrDotUpGrp);
            strDotUpGrp = new string(chrDotUpGrp);

            if (strDotUnderGrp.Length > 0)
                return strDotUpGrp + strDotUnderGrp;
            else
                return strDotUpGrp;
        }
Posted by 유령회사
|