How can I print a percentage value? Like, I have two integers, small_number and big_number. And I want to print “… “,small_number/big_number*100,” % …”, whole number only. Thanks!!
100 * small_number / big_number
Jeez… I stopped thinking about simple solutions when I read “Inform numbers are normally whole numbers in the range 32,768 to 32,767. Special programming is needed to represent larger numbers or fractions.” in the manual. But yeah, no fractions necessary. Thanks!
Expressions are evaluated from left to right. The interpreter doesn’t ever handle decimals, not even in intermediate results. So with the way you wrote it - let’s say small_number is 20 and big_number is 50:
20 / 50 = 0
0 * 100 = 0
As we change the order:
100 * 20 = 2000
2000 / 50 = 40
Note that with that method small_number can be at most 327 and the result is rounded down.
For small_number between 328 and 3276 you can use (small_number*10)/(large_number/10) which gives near-perfect results for big_number >1000