简体   繁体   English

进度条舍入到最接近的整数-VB.NET

[英]Progressbar rounding to nearest integer - VB.NET

I am having an issue with progress bars and can't seem to get them to show decimal values such as 0.5 or 4.1. 我在进度条上遇到问题,似乎无法让它们显示十进制值(例如0.5或4.1)。 When i set them as values with decimals it says "Property value is not valid". 当我将它们设置为带小数的值时,它会显示“属性值无效”。 It further says that "2.5 is not a valid value for Int32". 它进一步说“ 2.5不是Int32的有效值”。 Can't seem to find any solutions on these forums or anywhere else on the internet. 在这些论坛或互联网上的其他任何地方似乎都找不到任何解决方案。

Thanks 谢谢

EDIT : So there is no way for me to assign decimal values in a progress bar? 编辑:因此,没有办法让我在进度栏中分配十进制值吗?

Can't use decimals in a progress bar. 进度栏中不能使用小数。 I suggest you to multiply your value x10 times and set 5 for 0.5 and 41 for 4.1 我建议您将值乘以x10倍,将5设置为0.5,将41设置为4.1

You have to specify the value as an Integer. 您必须将值指定为Integer。 So if you want to show 0-100% with 0.1% increments you can just scale everything up by 10: 因此,如果您想以0.1%的增量显示0-100%,则可以将所有内容放大10:

ProgressBar1.Max = 1000

Then scale up the value by a factor of 10. So to show 4.1%: 然后将值放大10倍。因此显示4.1%:

ProgressBar1.Value = CInt(4.1 * 10)

If you want to have another digit of precision you could scale up further. 如果您想再提高一点精度,则可以进一步扩展。

The .Value property of the ProgressBar class is Defined as integer, so you cannot assign decimal values to it. ProgressBar类的.Value属性定义为整数,因此无法为其分配十进制值。

<BindableAttribute(True)> _
Public Property Value As Integer

If you want to show the progress percentage in decimal format, then you can place a label over it and print the value in that label. 如果要以十进制格式显示进度百分比,则可以在其上放置标签并在该标签中打印值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM