We’re rewarding the question askers & reputations are being recalculated! Read more.

# Tag Info

7

In calculator mode, { and } control how many digits are displayed.

6

You can use the built-in calc package to do so. Mark your expression, e.g. 3 * (1 + 1) Call calc-grab-region Call calc-dispatch (default C-x *), then hit g

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

4

You could use the fractional representation of numbers from calc. I am not sure why you think that passing the amount as string is inconvenient for the user. I would pass that input to calc and adapt the precision to the length of the string. Example: (calc-frac-mode 1) (setq str "999999999999999.01") (setq var-x (calc-eval (list (format "pfrac(%s)" str) ...

3

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

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

You can achieve highlighting of numbers in the buffers using highlight-numbers package. The face used for numbering is highlight-numbers-number and it inherits from font-lock-constant-face. For a deftheme the entry can be written as: '(highlight-numbers-number ((t (:foreground "#f0ad6d"))))

2

p From the manual, available in emacs here: (info "(calc)Precision") 7.2 Precision The ‘p’ (‘calc-precision’) command controls the precision to which floating-point calculations are carried. The precision must be at least 3 digits and may be arbitrarily high, within the limits of memory and time. This affects only floats: Integer and rational ...

2

The ?\C-j is the character representation of 10, in this case it's the same as control-j. For other values, it's more natural, for example 65, which is the ASCII value of A: 65 -> 65 (#o101, #x41, ?A)

2

What you're seeing is a byproduct of binary floating-point arithmetic. Non-integer decimal values generally don't have a representation in binary floating point that is truly equal. For many applications the difference or inaccuracy in representation isn't important, so applications can leverage the flexibility and performance of that format. The Emacs ...

2

For your specific example, you can also use C-M-% affiliation RET \&[\,(string (+ ?a \#))] RET C-M-% is the default binding of query-replace-regexp affiliation is regexp to search for \&[\,(string (+ ?a \#))] is the replacement pattern \& is the whole match, that is, affiliation \, runs a Lisp expression after it and captures the result (...

2

You probably want the make-string function. If count starts at 0 and counts up, then: (make-string 1 (+ ?a count)) will go a, b, c, etc.

2

You might also use calc's embedded mode if you intent to replace an expression with its result in the current buffer. C-u C-x * e when your formula / expression is on it's own on a separate line. Otherwise mark it and type C-0 C-x * e (Update: thanks to Dodgie, forgot to mention that) When you are finished with your mathematical manipulations type C-x * e ...

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

1

Your code contains an error: (e+3), it should be (+ e 3). When you run your command, Emacs will report the following error message in Echo Area and the *Messages* buffer goto-char: Symbol's function definition is void: e+3 Alternatively, you can insert at the end then at the beginning, so you don't need to +3 since b isn't moved at all. (defun wrap-in-...

1

You've answered your own question -- you're dealing with a number which is larger than most-positive-fixnum and are encountering floating point precision errors. The usual solution in Emacs is to use M-x calc. Type d 6 in the calc buffer to run calc-hex-radix (or d r to enter any supported radix value), and then all numbers will be displayed in hex. In ...

1

After read wvxvw and npostavs's comments, it's good to do it below: #+BEGIN_SRC elisp :results value (defun my/rep(str) (let ((val "") x y) (when (string-match "\\([0-9.]+\\),\\([0-9.]+\\)" str) (setq x (/ (string-to-number (match-string 1 str) 10) 2)) (setq y (/ (string-to-number (match-string 2 str) 10) 2)) (setq val (...

1

This is an easy one: p the number entered afterwards controls the precision of floating-point calculations.

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