VB.NET How to reduce int to 1 decimal point?

I use the code below to convert the file size in bytes (the test file is 31718 bytes) to KB (30.974609375 KB), but I want to map this to one decimal place (i.e. 30.9 KB). How can I do this in VB.NET?

New FileInfo(FileName).Length / 1024

thanks

+5
source share
3 answers
Math.Round(New FileInfo(FileName).Length / 1024,1)
+10
source

If it just displays the output you need, it is rounded, then use the format in ToString

Double.ToString("0.0")
+6
source

If you need it to be truncated but not rounded (as your example), then use Math.FLoor ()

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

All Articles