The function read-number truncates floating point zeros; e.g., (read-number "PROMPT: ") RET 100.00 => 100.0

I am seeking a similar alternative to read-number that will not truncate; e.g., (new-func "PROMPT: ") RET 100.00 => 100.00

  • 1
    Just on the off-chance that these values are money, and that they need to be absolutely precise, don't use floats, as they are inherently imprecise; a classic demonstration being (+ 0.1 0.2)
    – phils
    Commented Nov 27, 2020 at 0:59
  • 1
    And if that was a surprise, then floating-point-gui.de is your next port of call.
    – phils
    Commented Nov 27, 2020 at 1:08

1 Answer 1


If you enter 100.00 at the read-number prompt, then you get back a float, which might be printed differently to how it was entered.

For instance, 0.0000000000000000000001 prints in scientific notation as 1e-22

If you want Emacs to show the same thing that was typed, your best bet is to read a string.

If you just want to format the float differently, you can do that. E.g.:

(format "%.2f" (read-number "?"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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