|
From: | Jean Louis |
Subject: | 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 |
User-agent: | Mutt/2.2.9+54 (af2080d) (2022-11-21) |
(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/
[Prev in Thread] | Current Thread | [Next in Thread] |