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

Returns

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) eval-last-sexp-1(nil) eval-last-sexp(nil) call-interactively(eval-last-sexp nil nil) command-execute(eval-last-sexp) 

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

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

2
  • 1
    I think it's %%. Commented Jul 19, 2017 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. Commented Jul 20, 2017 at 21:53

1 Answer 1

6

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. 

Thus:

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

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.