GNU bug report logs - #59531
29.0.50: An alternative to `string-to-number` which throws an error (or returns a NIL value) when input is non-parseable as number

Previous Next

Package: emacs;

Reported by: Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>

Date: Thu, 24 Nov 2022 06:21:02 UTC

Severity: wishlist

Found in version 29.0.50

Full log


Message #19 received at 59531 <at> debbugs.gnu.org (full text, mbox):

From: Jean Louis <bugs <at> gnu.support>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 59531 <at> debbugs.gnu.org,
 Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>
Subject: Re: bug#59531: 29.0.50: An alternative to `string-to-number` which
 throws an error (or returns a NIL value) when input is non-parseable as
 number
Date: Fri, 16 Dec 2022 09:28:14 +0300
(defun string-is-number-p (s)
  "Return number only if string is actual number, otherwise NIL."
  (let* ((s (string-trim s)))
    (cond ((seq-empty-p s) nil)
	  ((string-match "[^0123456789\\.-]" s) nil)
	  ((string-match "-" s 1) nil)
	  ((numberp (string-to-number s)) (string-to-number s)))))


I use this function to make sure string is number and it
returns either the number of nil, and function is not
exhaustive.


Jean

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

In support of Richard M. Stallman
https://stallmansupport.org/





This bug report was last modified 2 years and 186 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.