金额拆分 "万千百"..

     

      很多情况下,比如存折,合同等都要这样表示金额,现在来看看如何实现:

   

View Code
<table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="10%" height="60" valign="middle" align="center">&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;</td>
                  <td width="90%" height="60" valign="middle" align="center"  ><table width="220" height="47" class="main_bg1 " border="0" cellspacing="0" cellpadding="0" >
                    <tr>
                      <td width="20" height="22" align="center" valign="middle"  class="main_bg2"></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg2"></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg2"></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg2"></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg2"></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg2"></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg2"></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg2"></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg2"></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg2"></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg2"></td>
                    </tr>
                    <tr>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg3"><asp:Literal ID="Literal1" runat="server"></asp:Literal></td>
                      <td width="20" height="22" align="center" valign="middle"  class="main_bg3"><asp:Literal ID="Literal2" runat="server"></asp:Literal></td>
                      <td width="20" height="22" align="center" valign="middle"  class="main_bg3"><asp:Literal ID="Literal3" runat="server"></asp:Literal></td>
                      <td width="20" height="22" align="center" valign="middle"  class="main_bg3"><asp:Literal ID="Literal4" runat="server"></asp:Literal></td>
                      <td width="20" height="22" align="center" valign="middle"  class="main_bg3"><asp:Literal ID="Literal5" runat="server"></asp:Literal></td>
                      <td width="20" height="22" align="center" valign="middle"  class="main_bg3"><asp:Literal ID="Literal6" runat="server"></asp:Literal></td>
                      <td width="20" height="22" align="center" valign="middle"  class="main_bg3"><asp:Literal ID="Literal7" runat="server"></asp:Literal></td>
                      <td width="20" height="22" align="center" valign="middle"  class="main_bg3"><asp:Literal ID="Literal8" runat="server"></asp:Literal></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg3"><asp:Literal ID="Literal9" runat="server"></asp:Literal></td>
                      <td width="20" height="22" align="center" valign="middle" class="main_bg3"><asp:Literal ID="Literal10" runat="server"></asp:Literal></td>
                      <td width="20" height="22" align="center" valign="middle"  class="main_bg3"><asp:Literal ID="Literal11" runat="server"></asp:Literal></td>
                    </tr>
                    
                  </table>

后台程序中:

 

View Code
 //将金额分解
    private void GetMoney(string num)
    {
        string money = num.ToString();
        int index1 = money.LastIndexOf(".") + 1;
        string zmoeny ="";
        if (money.LastIndexOf(".") == -1)
        {
            Literal11.Text = "0";
            Literal10.Text = "0";
            zmoeny = num;
        }
        else
        {
            zmoeny = money.Substring(0, index1 - 1);
            Literal11.Text = money.Substring(index1+11);
            Literal10.Text = money.Substring(index1, 1);
          
        }
        zcdate.Value = zmoeny;

        string[] dw = new string[9];
        int aa = dw.Length - zmoeny.Length;
        for (int i = dw.Length - 1; i >= 0; i--)
        {
            if (i >= aa)
            {
                dw[i] = zmoeny[i - aa].ToString();
            }
            else if(i==aa-1)
            {
                dw[i] = "";
            }else{
                dw[i] = "";
            }
        }
        Literal1.Text = dw[0].ToString();
        Literal2.Text = dw[1].ToString();
        Literal3.Text = dw[2].ToString();
        Literal4.Text = dw[3].ToString();
        Literal5.Text = dw[4].ToString();
        Literal6.Text = dw[5].ToString();
        Literal7.Text = dw[6].ToString();
        Literal8.Text = dw[7].ToString();
        Literal9.Text = dw[8].ToString();
    }

 

 上面是我自己写的,有什么不妥之处,希望大家指正!

posted @ 2011-10-09 12:16  双魂人生  阅读(456)  评论(0编辑  收藏  举报