Sompal Arya

Sompal Arya

  • NA
  • 286
  • 50.2k

how to convert 69,95,384 into 6995384

Mar 7 2014 11:46 AM
i have  a method for convert 6995384  into 69,95,384  .

       public static string CurrencyMethod(string val,bool IsDecimal=false)
        {
            var x = val;
            if (decimal.Parse(val) == 0 && IsDecimal)
            {
                return "0.0";
            }
            if (decimal.Parse(val) == 0)
            {
                return "0";
            }

            string sAfterPoint = x.Contains('.') ? '.' + x.Split('.')[1] : "";
            string sBeforePoint = x.Contains('.') ? x.Split('.')[0] : x;
            int sBeforePointLength = sBeforePoint.Length;
            string sBeforePointLastThree = "";
            string sBeforePointExceptLastThree = "";
            var allchar = "";
            if (sBeforePointLength > 3)
            {

                sBeforePointLastThree = sBeforePoint.Substring(sBeforePointLength - 3);
                sBeforePointExceptLastThree = sBeforePoint.Substring(0, sBeforePointLength - 3);
                if (sBeforePointExceptLastThree.Length % 2 == 0)
                {
                    if (sBeforePointExceptLastThree.Length > 0)
                    {
                        for (int i = 0; i < sBeforePointExceptLastThree.Length; i = (i + 2))
                        {
                            var f = sBeforePointExceptLastThree.Substring(i, 2);
                            allchar += f + ",";
                        }
                    }
                }
                else
                {
                    allchar = sBeforePointExceptLastThree.Substring(0, 1) + ",";
                    var restallchar = sBeforePointExceptLastThree.Substring(1, sBeforePointExceptLastThree.Length - 1);
                    if (restallchar.Length > 0)
                    {
                        for (int i = 0; i < restallchar.Length; i = (i + 2))
                        {
                            var f = restallchar.Substring(i, 2);
                            allchar += f + ",";
                        }
                    }
                }
            }
            else
            {
                sBeforePointLastThree = sBeforePoint;
            }
            return allchar + sBeforePointLastThree + sAfterPoint;
        }


But i want to do vice versa  69,95,384 into   6995384 .help me...



Answers (3)