简体   繁体   中英

VB.NET How do I reduce int to 1 decimal place?

I'm using the code below to convert the file size in bytes (test file is 31718 bytes) to KB (30.974609375 KB) but I want to display this to one decimal place (ie 30.9 KB). How would I do this in VB.NET?

New FileInfo(FileName).Length / 1024

Thanks

Math.Round(New FileInfo(FileName).Length / 1024,1)

如果它只是显示输出,你需要它舍入,然后使用ToString中的格式

Double.ToString("0.0")

如果你需要它被截断,但不是圆形(如你的例子所示),那么使用Math.FLoor()

   Decimal val = Math.Floor(New FileInfo(FileName).Length / 102.4) / 10;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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