Function: calculator-remove-zeros

calculator-remove-zeros is a byte-compiled function defined in calculator.el.gz.

Signature

(calculator-remove-zeros NUMSTR)

Documentation

Get a number string NUMSTR and remove unnecessary zeros.

The behavior of this function is controlled by calculator-remove-zeros(var)/calculator-remove-zeros(fun).

Source Code

;; Defined in /usr/src/emacs/lisp/calculator.el.gz
(defun calculator-remove-zeros (numstr)
  "Get a number string NUMSTR and remove unnecessary zeros.
The behavior of this function is controlled by
`calculator-remove-zeros'."
  (let* ((s (if (not (eq calculator-remove-zeros t)) numstr
                ;; remove all redundant zeros leaving an integer
                (replace-regexp-in-string
                 "\\.0+\\([eE].*\\)?$" "\\1" numstr)))
         (s (if (not calculator-remove-zeros) s
                ;; remove zeros, except for first after the "."
                (replace-regexp-in-string
                 "\\(\\..[0-9]*?\\)0+\\([eE].*\\)?$" "\\1\\2" s))))
    s))