![](/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.