![](/img/trans.png)
[英]Displaying floating-point number as a percentage without changing the value of the number
[英]How to convert .NET Trackbar control integer value to floating-point percentage
當我這樣做時,我總是得到0的百分比:
int trackBarValue = trackBar.Value;
float percentage = trackBarValue / 100;
我的代碼有什么問題?
問題是您正在執行整數除法,該除法將被截斷。 嘗試這個:
int trackBarValue = trackBar.Value;
float percentage = trackBarValue / 100.0;
這將進行浮點除法,並為您提供所需的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.