"Floating-point numbers with this negative exponent or lower are displayed
scientific notation in calc-mode.")
+(defvar calc-digit-after-point nil
+ "If t, display at least one digit after the decimal point, as in `12.0'.
+If nil, the decimal point may come last in a number, as in `12.'.
+This setting only applies to floats in normal display mode.")
+
(defvar calc-other-modes nil
"List of used-defined strings to append to Calculator mode line.")
exp (- exp adj)))))
(setq str (int-to-string mant))
(let* ((len (length str))
- (dpos (+ exp len)))
+ (dpos (+ exp len))
+ (trailing-0 (and calc-digit-after-point "0")))
(if (and (eq fmt 'float)
(<= dpos (+ calc-internal-prec calc-display-sci-high))
(>= dpos (+ calc-display-sci-low 2)))
(setq str (concat "0" point str)))
((and (<= exp 0) (> dpos 0))
(setq str (concat (substring str 0 dpos) point
- (substring str dpos))))
+ (substring str dpos)
+ (and (>= dpos len) trailing-0))))
((> exp 0)
- (setq str (concat str (make-string exp ?0) point)))
+ (setq str (concat str (make-string exp ?0)
+ point trailing-0)))
(t ; (< dpos 0)
(setq str (concat "0" point
(make-string (- dpos) ?0) str))))
(let ((calc-number-radix 36))
(should (equal (math-format-number 12345678901) "36#5,O6A,QT1")))))
+(ert-deftest calc-digit-after-point ()
+ "Test display of trailing 0 after decimal point (bug#47302)."
+ (let ((calc-digit-after-point nil))
+ ;; Integral floats have no digits after the decimal point (default).
+ (should (equal (math-format-number '(float 0 0)) "0."))
+ (should (equal (math-format-number '(float 5 0)) "5."))
+ (should (equal (math-format-number '(float 3 1)) "30."))
+ (should (equal (math-format-number '(float 23 0)) "23."))
+ (should (equal (math-format-number '(float 123 0)) "123."))
+ (should (equal (math-format-number '(float 1 -1)) "0.1"))
+ (should (equal (math-format-number '(float 54 -1)) "5.4"))
+ (should (equal (math-format-number '(float 1 -4)) "1e-4"))
+ (should (equal (math-format-number '(float 1 14)) "1e14"))
+ (should (equal (math-format-number 12) "12")))
+ (let ((calc-digit-after-point t))
+ ;; Integral floats have at least one digit after the decimal point.
+ (should (equal (math-format-number '(float 0 0)) "0.0"))
+ (should (equal (math-format-number '(float 5 0)) "5.0"))
+ (should (equal (math-format-number '(float 3 1)) "30.0"))
+ (should (equal (math-format-number '(float 23 0)) "23.0"))
+ (should (equal (math-format-number '(float 123 0)) "123.0"))
+ (should (equal (math-format-number '(float 1 -1)) "0.1"))
+ (should (equal (math-format-number '(float 54 -1)) "5.4"))
+ (should (equal (math-format-number '(float 1 -4)) "1e-4"))
+ (should (equal (math-format-number '(float 1 14)) "1e14"))
+ (should (equal (math-format-number 12) "12"))))
+
(ert-deftest calc-calendar ()
"Test calendar conversions (bug#36822)."
(should (equal (calcFunc-julian (math-parse-date "2019-07-27")) 2458692))