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

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

Re: str-to-int


From: Bruno Félix Rezende Ribeiro
Subject: Re: str-to-int
Date: Tue, 07 Apr 2020 20:04:04 -0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Hi Emanuel,

Emanuel Berg via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

> ;; 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

How about (str-to-int "00") => nil?

-- 
Bruno Félix Rezende Ribeiro (oitofelix) [0x28D618AF]
<http://oitofelix.freeshell.org/>

Attachment: signature.asc
Description: PGP signature


reply via email to

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