FileSizeEx and Integer Math
Keywords: FileSizeEx and integer math
Question:
Maybe I'm hitting a max-int or something, but I'm kinda confused.When I do this:
FILE_SIZES=FileSizeEx(strcat(CD_PATH,"*.*")) FREE_SPACE=2851000000-FILE_SIZES DISP_SIZE=((FILE_SIZES / 1000) / 1000) DISP_SIZE=strcat(DISP_SIZE," MB") ========================================FREE_SPACE returns a positive number.
2146681977 or 2.14 gigthe FILE_SIZES is actually 704 mb
704318023However, if I go over 2.85 gig minus File_Sizes, it returns a negative number.
FREE_SPACE=2900000000-FILE_SIZES
returns -2099285319
What am I missing here ?
Answer:
You are doing integer math, and the largest integer WinBatch can handle is about 2.1 billion. You are going over that to 2.85 billion.Simple fix...Add the Decimals(0) and the .0 to your big number.
And you might want to change your divisor as indicated to match windows.
Decimals(0) FILE_SIZES=FileSizeEx(strcat(CD_PATH,"*.*")) FREE_SPACE=2851000000.0-FILE_SIZES DISP_SIZE=((FILE_SIZES / 1000) / 1024) DISP_SIZE=strcat(DISP_SIZE," MB")So basically use a real instead of an int.
Article ID: W15150