C# How do I shorten my double when I converted bytes to megabytes? -


hello made updater downloads update files used bytes indication now
found way convert megabytes,

works 1 little problem returns huge numbers example,
file 20mb displayed : 20.26496724167345 mb

how make number bit shorter 20.26mb

this code converts mb :

    static double b2mb(long bytes)     {         return (bytes / 1024f) / 1024f;     } 

you can use math.round round specified number of digits. if want two, in case, use so: math.round(inputvalue, 2);. code this:

static double b2mb(long bytes) {     return math.round((bytes / 1024f) / 1024f, 2); } 

note: because floating point numbers don't have infinite precision, may result in 24.24999999999999999 instead of 24.25. method worth knowing, if you're outputting string, should @ using formatting strings, other answers do.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -