Unable to get first 2 digits from double

Hello,

I am calulating zip file size using below formula
new System.IO.FileInfo(path).Length
and this is returning in kb.
i want size in MB so i am deviding value by 1000 and assigning to variable MB which is having double datatype.
now i am getiing value like 25556.989 this if file size is 25 mb
but i only want 25 from this number .
how can i get that?
please check below ss.
1

path - string - my file path
filesize - int64 - new System.IO.FileInfo(path).Length
MB - double - filesize/1000
Help me to solve this issue

Try this:

Math.Round(doubleVar,2,MidpointRounding.AwayFromZero)

Reference: Adjust double data type to take only the first 2 decimals - #2 by Yoichi

it is changing just last 2 digits
1

Try math.Round((MB/1024),0)

grafik

2 Likes

Thanks ,worked

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.