Hot answers tagged

5

My favourite method for summing a column: Mark one corner of the rectangle Move point to the opposite corner Type C-x*: Acting on a rectangle is useful because it still works as-is if the numbers are actually a column within a bunch of other text. In more detail: C-x* calls calc-dispatch which has keys specifically for summing rectangles -- : and _ call ...


3

For numeric calculation there is a parallel universe within Elisp: Calc. The division operator / within defmath works with the floating numbers of Calc. Nevertheless, the interface of Calc with the Elisp world is a bit complicated. You need to convert floating point numbers to strings. These strings are then converted by Calc to their Calc-internal ...


3

The following Elisp code demonstrates how you can define your own wrapper macro with-float/ that treats all explicit occurences of / in its body as division of floats. Division operators that are used in functions called within the body of with-float/ are the original operators. (defmacro with-float/ (&rest body) "Evaluate BODY with / for float ...


3

Wrap the numbers in (+ ...), that is insert (+ at the beginning and ) at the end, then hit C-x C-e (eval-last-sexp).


2

(defun sum-it-up () "Sum the whole buffer if no active region, or just the active region (if applicable). Copy the result to the kill ring. The result is thrown just in case anyone needs it." (interactive) (let* (draft (region-active-p (region-active-p)) (reg-beg (when region-active-p (region-beginning))) (reg-end (when region-...


1

You can use this org table formula, format is used to ensure the number's width is 2 and padded with zero, as @sds's answer suggested: #+NAME: addition-table | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |---+----+----+----+----+----+----+----+----+----+----| | 0 | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | | 1 | 01 | 02 | 03 | 04 | 05 | 06 ...


1

TL;DR You need to format your numbers with the leading zeros if you want them: (format "%03d" 3) ==> "003" Details When you type (defvar foo '(00 01 02)) and evaluate it, Emacs reads the string "01" and recognizes it as a number (integer) and stores it in the list. Then it promptly forgets how the number was represented - as "1" or "01" or "000001". ...


1

You can also integrate other commands to help, e.g. awk: Mark the region containing the lines of numbers. Type M-| ( shell-command-on-region ), and input awk '{s+=$1}END{print s}', which means summing up every lines in the region. It will display the result in echo area, 72507 in this case. Or if you like to replace the region with the sum, just prefix the ...


1

... a way to search for and delete numerals above a certain value I think column-based solutions make more sense in this case but, just for fun, here's an interactive way you could delete numerals above a certain value using search-and-replace: M-x replace-regexp RET \b\([0-9]\{6,\}\)\b RET \,(if (> \#1 164000) "" \1) RET Which will turn your example ...


1

(random t) ; seed it randomly (defun my-random-number-insert-at-point () "Insert at point a four-digit random number between 0000 to 1000." (interactive) (insert (number-to-string (random 100))))


1

The following should work: M-x query-replace-regexp RET \([0-9]+\) RET \,(string (+ (1- ?a) \#1)) RET


Only top voted, non community-wiki answers of a minimum length are eligible