Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我这样做时,我总是得到 0 的百分比:
int trackBarValue = trackBar.Value; float percentage = trackBarValue / 100;
我的代码有什么问题?
问题是你正在做一个整数除法,它被截断了。试试这个:
int trackBarValue = trackBar.Value; float percentage = trackBarValue / 100.0;
这将进行浮点除法,并为您提供所需的结果。