-1
我正在編碼一個簡單的計算器,它需要顯示小數點後兩位數字,但我無法弄清楚。該程序的其餘部分完美工作,商標按鈕也是如此,但它只是在小數點後顯示太多數字。下面是我有:如何在C#中使用雙精度型數字獲得小數點後兩位數的數字?
private double _leftop = 0;
private double _rightop = 0;
private double _quotient = 0;
private void BtnQuotient_Click(object sender, EventArgs e)
{
if (Double.TryParse(TxtLeftOperand.Text, out _leftop) == true && Double.TryParse(TxtRightOperand.Text, out _rightop) == true)
{
_quotient = _leftop/_rightop;
TxtResult.Text = Convert.ToString(_quotient);
}
else
{
TxtResult.Text = "Error";
}
}
你想用兩位數顯示_或者轉換成兩位數嗎?前者你可以在輸出上使用'Format'作爲字符串,後者可以用下面的答案發表,你可以使用'Math.Round()'。 –
'TextResult.Text = _quotient.ToString(「f2」);' – DhavalR