First of all, if for example free-hdd-space=113070080 and total-hdd-space=134217728
this operation
($totalhdd - $freehdd / $totalhdd * 100)
is = to
(134217728 - 113070080 / 134217728 * 100)
and the result inside routeros is (134217728 - 0 * 100) = (134217728 - 0) = 134217728 the total hdd space
Because / and * take precedence over -
The correct operation to have "% freehdd space" from the proportion
$totalhdd : 100 = $freehdd : x
x = (100 * $freehdd) / $totalhdd
The division must be last operation, because RouterOS do not support floating values.
If you want decimals, multiply the numbers by 10, 100, etc. before the division, and use [:pick] for add the comma/dot (language specific)
{
/system resource
:local totalhdd [get total-hdd-space]
:local freehdd [get free-hdd-space]
:local percfree ((100 * $freehdd) / $totalhdd)
:put "Space: Total $totalhdd, Free $freehdd"
:put "$percfree% free disk space, $(100 - $percfree)% busy"
# 2 decimals = 2 significant zeros (for prevent results under 1,00% like _,_0%), number * 100 and :pick the last 2 digit
:local perdec "00$((100 * $freehdd * 100) / $totalhdd)"
:set perdec "$[:tonum [:pick $perdec 0 ([:len $perdec]-2)]],$[:pick $perdec ([:len $perdec]-2) [:len $perdec]]"
:put "$perdec% free disk space"
}
If you want "nice" formatted space(s) value on MiB (RouterOS style is MiB with 1 decimal):
{
/system resource
:local totalhdd [get total-hdd-space]
:local freehdd [get free-hdd-space]
:set totalhdd "0$(($totalhdd * 0xA) / 0x100000)"
:set totalhdd "$[:tonum [:pick $totalhdd 0 ([:len $totalhdd]-1)]],$[:pick $totalhdd ([:len $totalhdd]-1) [:len $totalhdd]]"
:set freehdd "0$(($freehdd * 0xA) / 0x100000)"
:set freehdd "$[:tonum [:pick $freehdd 0 ([:len $freehdd]-1)]],$[:pick $freehdd ([:len $freehdd]-1) [:len $freehdd]]"
:put "Space: Total $totalhdd MiB, Free $freehdd MiB"
}