[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: bike shifting - output decimal in percent
From: |
Drew Adams |
Subject: |
RE: bike shifting - output decimal in percent |
Date: |
Sun, 19 May 2019 14:26:26 +0000 (UTC) |
> the original program is _much_ better:
>
> ;; test - should be 43% for
> ;; (bike-compute-step 42 24) ; "43%"
>
> ;; (percent-string 0.01) ; "1%"
> ;; (percent-string 0.1) ; "10%"
> ;; (percent-string 1) ; "100%
> ;; (percent-string 2) ; "200%"
>
> ;; (format "%2.2g%%" (* 100.0 0.01)) ; " 1%" (?)
> ;; (format "%2.2g%%" (* 100.0 0.1)) ; "10%"
> ;; (format "%2.2g%%" (* 100.0 1)) ; "1e+02%" (!?)
> ;; (format "%2.2g%%" (* 100.0 2)) ; "2e+02%" (...)
It all depends on what you want and what your expected
input is.
(format "%1.1d%%" (* 100.0 0.01)) ; "1%"
(format "%1.1d%%" (* 100.0 0.1)) ; "10%"
(format "%1.1d%%" (* 100.0 1)) ; "100%"
(format "%1.1d%%" (* 100.0 2)) ; "200%"
(format "%1.1d%%" (round (* 100.0 0.42857142857142855))) ; "43%"
(defun percent-string (decimal)
(format "%2.1d%%" (round (* 100.0 decimal))))
Like I said (regarding CL `format', but the same is true
of Emacs-Lisp `format': it's a language unto itself.
- bike shifting - output decimal in percent, Emanuel Berg, 2019/05/18
- RE: bike shifting - output decimal in percent, Drew Adams, 2019/05/18
- RE: bike shifting - output decimal in percent, Drew Adams, 2019/05/19
- Re: bike shifting - output decimal in percent, Emanuel Berg, 2019/05/19
- Re: bike shifting - output decimal in percent, Emanuel Berg, 2019/05/19
- Re: bike shifting - output decimal in percent, Tomas Nordin, 2019/05/19
- Re: bike shifting - output decimal in percent, Emanuel Berg, 2019/05/19
- Re: bike shifting - output decimal in percent, Tomas Nordin, 2019/05/19
- Re: bike shifting - output decimal in percent, Emanuel Berg, 2019/05/19
- RE: bike shifting - output decimal in percent,
Drew Adams <=
- RE: bike shifting - output decimal in percent, Drew Adams, 2019/05/19