1

To convert from percent to decimal:  divide by 100, and remove the "%" sign.

The snippet (/ PERCENT 100) yields a seemingly unexpected result. E.g., Converting 50% to a decimal should yield 0.5; however, (/ 50 100) returns 0.

Tentative workaround pending an answer: (* PERCENT .01)

lawlist
  • 18,826
  • 5
  • 37
  • 118

1 Answers1

4

Your workaround tells the whole story:

(/ 1 2) ;=> 0
(/ 1.0 2) ;=>0.5

With integers, emacs does integer arithmetic, with floats it does floating-point arithmetic.


See the Elisp manual, node Arithmetic Operations:

Except for %, each of these functions accepts both integer and floating-point arguments, and returns a floating-point number if any argument is floating point.

And, for /:

If all the arguments are integers, the result is an integer, obtained by rounding the quotient towards zero after each division.

See also node Numeric Conversions, for info about explicitly converting among numeric types.

Drew
  • 75,699
  • 9
  • 109
  • 225
Fran Burstall
  • 3,665
  • 10
  • 18