[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bike shifting - output decimal in percent
From: |
Emanuel Berg |
Subject: |
bike shifting - output decimal in percent |
Date: |
Sun, 19 May 2019 03:34:07 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) |
How do I output a decimal float digit
0 <= x <= 1 into percent? ("A percentage?"
Correct English?)
I asked at #emacs@irc.freenode.net and got the
below answer, which, as you see, works fine.
But I wonder if/why-not there is/isn't
a built-in way to do it?
Context:
;; thanks to friend at #emacs
(defun percent-string (decimal)
(concat
(number-to-string
(round (* 100 decimal)) ) "%") )
;; test: (percent-string 0.42857142857142855) ; "43%"
(defun bike-compute-step (from to)
(percent-string
(/ (- from to)
from
1.0) ))
;; test - should be 43% for
;; one 42t and one 24t chainring
;; according to an article in the spring 2019 issue
;; of "Bicycle Quarterly" (ISSN 1941-8809) -
;; (bike-compute-step 42 24) ; "43%"
Whole file:
http://user.it.uu.se/~embe8573/emacs-init/bike.el
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
- bike shifting - output decimal in percent,
Emanuel Berg <=
- 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, 2019/05/19