View Full Version : سوال: تابعی برای جدا کردن سه رقم سه رقم اعداد با ویرگول
  
ندااحمدی
یک شنبه 09 بهمن 1390, 13:45 عصر
تابعی میخواهم  برای جدا کردن سه رقم سه رقم اعداد با ویرگول به عنوان مثال 123456789 به 123,456,789
hamid_shrk
یک شنبه 09 بهمن 1390, 13:56 عصر
سلام
بفرمایید :
public string ViewUserPrice(int price)
        {
            string strPrice =price.ToString();
            if (strPrice.Length > 3)
            {
                int counter = 0;
                for (int i = strPrice.Length; i >=1 ; i--)
                {
                    
                    if (counter!=0 && counter % 3 == 0)
                    {
                        strPrice = strPrice.Insert(i, ",");
                    }
                    counter++;
                }
            }
            return (strPrice);
        }
M.KH-SH
یک شنبه 09 بهمن 1390, 14:22 عصر
C#:
public string @add(Int64 i) {     return Strings.Format(i, "###,###,###,###"); }
VB:
 Function add(ByVal i As Int64) As String
        add = Format(i, "###,###,###,###")
    End Function
programer-ir
یک شنبه 09 بهمن 1390, 14:30 عصر
البته این ها همه سمت سرور باید جاوااسکریپت نوشته بشه هما شیوه کار همینه تقریبا.........
hamid_shrk
یک شنبه 09 بهمن 1390, 14:37 عصر
اینم فانکشن جاوا اسکریپتش :
<script type="text/javascript" language="javascript">
    //<![CDATA[
        function UserPrice(Price) {
            var newprice = String(Price);
            if (newprice.length > 3) {
                var counter = 0;
                for (var i = newprice.length; i >= 1; i--) {
                    if (counter != 0 && counter % 3 == 0) {
                        var pretext = newprice.substring(0, i);
                        var posttext = newprice.substring(i, newprice.length);
                        newprice = pretext + "," + posttext;
                    }
                    counter++;
                }
            }
            return (newprice);
        }
     // ]]>
    </script>
ندااحمدی
یک شنبه 09 بهمن 1390, 17:08 عصر
ممنون از راهنماییتون
ولی من تابع javascript نمیخواستم
asp2.net
یک شنبه 09 بهمن 1390, 17:37 عصر
مشکلتون حل شد؟
ندااحمدی
یک شنبه 09 بهمن 1390, 18:13 عصر
خیر من تابع javascript نمیخواستم
parvizwpf
یک شنبه 09 بهمن 1390, 18:20 عصر
double bes
 double.TryParse(lblJamBes.Text, out Bes);
                    lblJamBed.Text = string.Format("{0:N0}", Bed);
hamid_shrk
یک شنبه 09 بهمن 1390, 18:30 عصر
ممنون از راهنماییتون
ولی من تابع javascript نمیخواستم
 اولی که جاوا اسکریپت نبود.
ازش استفاده کنید دیگه.
من دوتاش رو گذاشتم و این دوتا بهم اصلا وابسته نیستنااا
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.