From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: bike shifting - output decimal in percent Date: Sun, 19 May 2019 14:26:26 +0000 (UTC) Message-ID: <0389094e-82aa-42e3-86cb-747c063cf044@default> References: <86mujjrzw0.fsf@zoho.eu> <3b5af744-8dc6-42d0-9273-a8030e2b3443@default> <86blzysz4e.fsf@zoho.eu> <867eamsxq2.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="225673"; mail-complaints-to="usenet@blaine.gmane.org" To: Emanuel Berg , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun May 19 16:28:42 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hSMnq-000wbR-Jt for geh-help-gnu-emacs@m.gmane.org; Sun, 19 May 2019 16:28:42 +0200 Original-Received: from localhost ([127.0.0.1]:49461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSMnp-0002Zq-2F for geh-help-gnu-emacs@m.gmane.org; Sun, 19 May 2019 10:28:41 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:57466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSMnf-0002Zi-4y for help-gnu-emacs@gnu.org; Sun, 19 May 2019 10:28:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSMne-0002jM-9E for help-gnu-emacs@gnu.org; Sun, 19 May 2019 10:28:31 -0400 Original-Received: from userp2120.oracle.com ([156.151.31.85]:44990) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hSMne-0002is-0j for help-gnu-emacs@gnu.org; Sun, 19 May 2019 10:28:30 -0400 Original-Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x4JEJG8l112970; Sun, 19 May 2019 14:28:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=aKVrYBXhKbwIQ/C1s1A+auaXtqdEPNrGAoFexYh9OYQ=; b=hHXvXJRBBHzARqQMVlHBBh1cUkgc2cO6Xv87EpqLIiSXjcoHgKRVB0NomPIOnSk75b5g CiyqjF+BpROE65J9ggSvNP47HgZ2AaN0cx4/Iog/cok288HlkjJG9XPR71F9qMq4hxaU LRP7tL7sSll6jYgDf6cAQnyBECd6QtruzbasRFgKkkpFMYBkejyO+vlX8e1NBj+otool aiGkYTG+6jJASUjPSAWodBCYgd9xgF/U4M7oPyWw7QEPBtzqL67IUCQqkCj9u5WY9qAw NS2tkCobMBov9gHNL4zl7HYyKa6qqg/9dqZlb55yNt73VT4LTjxwuWdHPsZ6ZkR+1M9m Cw== Original-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2sjapq359g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 19 May 2019 14:28:28 +0000 Original-Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x4JEPTFL190829; Sun, 19 May 2019 14:26:27 GMT Original-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 2sjwqqwdab-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 19 May 2019 14:26:27 +0000 Original-Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x4JEQQPd010038; Sun, 19 May 2019 14:26:27 GMT In-Reply-To: <867eamsxq2.fsf@zoho.eu> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4849.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9261 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=934 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905190105 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9261 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=965 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905190105 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:120547 Archived-At: > the original program is _much_ better: >=20 > ;; test - should be 43% for > ;; (bike-compute-step 42 24) ; "43%" >=20 > ;; (percent-string 0.01) ; "1%" > ;; (percent-string 0.1) ; "10%" > ;; (percent-string 1) ; "100% > ;; (percent-string 2) ; "200%" >=20 > ;; (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.