2014-03-02 51 views
-1

我這樣做對我的部門代碼,而不是號碼,如10.55555或2.55555轉出,怎麼能縮短至10.555和2.555縮短分頻比

decimal d = numericUpDown1.Value/numericUpDown2.Value; 
label1.Text = "Ratio: " + d.ToString(); 
+4

爲什麼選擇定時器?輸入可能有某種「改變」事件。收聽該事件並在其被觸發時重新計算。 –

+0

它不一定是一個計時器,我只是喜歡它自動。任何其他方法都很好,但提示或建議? @ChrisSinclair –

+0

http://stackoverflow.com/questions/1979213/event-which-occurs-when-form-is-focused這裏是你的問題的一個很好的解決方案。 – user1767754

回答

1

嘗試

decimal d = numericUpDown1.Value/numericUpDown2.Value ; 
label1.Text = string.Format("Ratio: {0}" , 
       Math.Round(d,3) , 
       MidpointRounding.ToEven 
       ) ; 

decimal d = numericUpDown1.Value/numericUpDown2.Value ; 
label1.Text = string.Format("Ratio: {0:0.000}" , 
       Math.Round(d,3) , 
       MidpointRounding.ToEven 
       ) ; 
+0

是的!第二個正是我想要的。謝謝! –