unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* What is 0.01 here not 0.01 here 0.009999999999999?
@ 2021-04-02 13:42 Jean Louis
  2021-04-02 13:56 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Jean Louis @ 2021-04-02 13:42 UTC (permalink / raw)
  To: Help GNU Emacs

I would like to get a number increased for 0.01:

(defun rcd-vc-increase-decimal-revision-number (nn.nn)
  (let* ((nn.nn (format "%s" nn.nn))
	 (nn.nn (format "%.2f" (string-to-number nn.nn)))
	 (nn.nn (string-to-number nn.nn)))
    (+ nn.nn 0.01)))

But result is not what I want, as I want to get 10.13, though it is
tiny loss:

(rcd-vc-increase-decimal-revision-number "10.12") → 10.129999999999999

I found how to solve it, but maybe there is better way to round the
decimals behind the dot?

(defun rcd-vc-increase-decimal-revision-number (nn.nn)
  (let* ((nn.nn (format "%s" nn.nn))
	 (nn.nn (format "%.2f" (string-to-number nn.nn)))
	 (nn.nn (string-to-number nn.nn)))
    (string-to-number (format "%.2f" (+ nn.nn 0.01)))))

(rcd-vc-increase-decimal-revision-number "10.12") → 10.13


Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://rms-support-letter.github.io/




^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-04-19 10:51 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-02 13:42 What is 0.01 here not 0.01 here 0.009999999999999? Jean Louis
2021-04-02 13:56 ` Stefan Monnier
2021-04-02 17:03   ` Jean Louis
2021-04-02 17:41     ` Teemu Likonen
2021-04-02 18:44       ` Jean Louis
2021-04-02 20:46     ` John Yates
2021-04-02 21:19       ` Jean Louis
2021-04-02 22:04         ` John Yates
2021-04-02 23:29           ` Jean Louis
2021-04-03  4:39             ` Arthur Miller
2021-04-03  5:36               ` Jean Louis
2021-04-03  3:56     ` Arthur Miller
2021-04-03  5:19       ` Jean Louis
2021-04-03 13:54         ` Stefan Monnier
2021-04-02 14:02 ` Eli Zaretskii
2021-04-02 17:07   ` Jean Louis
2021-04-03  4:49     ` Arthur Miller
2021-04-16 20:41 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-17 10:53   ` Jean Louis
2021-04-19 10:51   ` Eric S Fraga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).