How to set a variable to another variable that is multiplied by a fraction in a batch file?

StackOverflow https://stackoverflow.com/questions/21586236

Вопрос

I need to create a batch file that is able to take a %FREEMEMORY% variable that represents a number and multiply that variable by 0.09 and set the product of that equation as another variable using this name: %MEMORYTOUSE%. I need to be able to round the product down to the nearest whole number.

I just need to know how to multiply any number by 0.09 and then round it down to the nearest whole number.

Это было полезно?

Решение

There are no decimals in batch arithmetic. All the calcs are with 32 bit integers (31 bit numbers plus a sign bit), with data values in the range -2147483648 to 2147483647. So what you need is

set /a "memoryToUse=%freeMemory% * 9 / 100"

Of course, limited to the indicated range of values.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top