help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

str-to-int


From: Emanuel Berg
Subject: str-to-int
Date: Sat, 07 Mar 2020 02:12:49 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

;; better than string-to-number

(defun str-to-int (str)
  (if (string= str "0") 0
    (let ((res (string-to-number str)))
      (if (= res 0) nil (round res)) )))

;; (string-to-number "love and pain / it never stays the same") ; 0
;; ... ???
;;
;; (string-to-number "0") ; 0 ... well, correct! by all means

;; (str-to-int "give me all the storybook told me") ; nil
;; (str-to-int "the power and the glory till thy kingdom come") ; nil
;; (str-to-int "0")     ; 0
;; (str-to-int "1337")  ; 1337
;; (str-to-int "1.337") ; 1
;; (str-to-int "1.9")   ; 2
;; (str-to-int "0.1")   ; 0

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]