using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication1{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){}private void button1_Click(object sender, EventArgs e){double corpusAmount, interestRate,interestAmount, incomeAmount;int depositYear; //本金,利率,利息,總收入,存期try // 錄入數據{corpusAmount = double.Parse(this.corpusTextbox.Text);interestRate = double.Parse(this.interestRatetextBox.Text);depositYear = Int32.Parse(this.depositYeartextBox3.Text);}catch //異常處理{MessageBox.Show(" Input dismatached !");return;}incomeAmount = corpusAmount * (Math.Pow((1 + interestRate), depositYear)); //計算總收入interestAmount = incomeAmount - corpusAmount; //計算利息//格式化列表string strList;strList = string.Format(" {0,15:c } {1,15:c } ", interestAmount, incomeAmount);listBox1.Items.Add(strList); //輸出```}}}
3 回答

陪伴而非守候
TA貢獻1757條經驗 獲得超8個贊
c后面 不要空格
double value1 = 16932.456;
double value2 = 15421.354;// {0,15:c } {1,15:c } 這個有空格 錯誤的
string result = String.Format("{0,15:c} {1,15:c}", value1, value2);

躍然一笑
TA貢獻1826條經驗 獲得超6個贊
strList = string.Format(" {0,15:c } {1,15:c } "
這個是啥?{}里面不是占位符吧
format的用法是string.Format("{0},{1}",value1,value2);
{0}{1}都是占位符,分別對應value1和value2的值

繁星淼淼
TA貢獻1775條經驗 獲得超11個贊
返回的是2個double數值,一個得息,一個總收到,你用string.Format把他們轉換成字符串,比如一個數是10.59,另一個數是11.49,stringList="10.59$11.49$"(15:C應該表示貨幣吧),你查下interestAmount,和incomeAmount有值么?
- 3 回答
- 0 關注
- 160 瀏覽
添加回答
舉報
0/150
提交
取消