(format "Hard-coded value is 100\% and the variable is %s" "50\\%")


Debugger entered--Lisp error: (error "Invalid format operation %a")
  format("Hard-coded value is 100% and the variable is %s" "50%")
  eval((format "Hard-coded value is 100% and the variable is %s" "50%") nil)
  call-interactively(eval-last-sexp nil nil)

(Note how in the debugger output, the command has the "%" escaped)

How in heaven can I use a string with a percentage in it?

  • 1
    I think it's %%.
    – politza
    Jul 19 '17 at 22:16
  • Elisp manual, node Formatting Strings. You can get to that just by using C-h i, choosing the Elisp manual, and i format RET.
    – Drew
    Jul 20 '17 at 21:53

It is indeed %%. If you type C-h f format <RET> you'll pull up the documentation for the format function, which states:

Use %% to put a single % into the output.


(format "Hard-coded value is 100%% and the variable is %s" "50%")

(the % signs never need to be escaped with backslashes).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.