Math with Percentages?

Does anyone know of a way to do math with percentages? I want to multiply a number, say 1024 by a percentage, say 80%. So I would have assumed I could just do something like this 1024 * .8. However it looks like decimal points aren’t supported so I’m not sure what to do. Any suggestions?

I figured out a simple way around it. I just multiply by 80 and then divide by 100. I loose some decimal points of precision but for my purposes it’s not a problem.

I do similar in some of my scripts, basically.. keep your values in bytes and do your calculations on that, then just display your end figures in Mb or Gb when needed.

Otherwise yeah, you’ll lose a lot of info if you start trying to work out percentages in GB etc.

Here is a precise way of calculating exact values with decimals (works with or without decimal numbers).

To use this in scripts you could create a global variables for dividend, divisor, and result then run this math script, setting the result variable for use in the calling script.

# Preforms calculation with decimal points
# dividend / divisor = quotient.decimal

:local dividend 3
:local divisor 11
:local decimalplaces 3


# Math Calculation here
:local quotient 0
:local remainder 0
:local result 0
:local decimal 0

:set quotient ($dividend / $divisor)

:if ($quotient = 0) do={
  :set dividend [:tonum ($dividend . "0")]
}

:set remainder ($dividend - ($divisor * $quotient))

:if ($remainder > 0) do={
  :local tmpremainder [:tonum ($remainder . "0")]
  :for x from=1 to=$decimalplaces do={
    :local tmpdecimal [:tonum ($tmpremainder / $divisor)]
    :set decimal [:tonum ($decimal . $tmpdecimal)]
    :set tmpremainder [:tonum (($tmpremainder - ($tmpdecimal * $divisor)) . "0")]
  }
  :set result ($quotient . "." . $decimal)
} else={
  :set result $quotient
}
# END Math Calculation here

:put ($dividend . " / " . $divisor . " = " . $result)