Skip to content

Instantly share code, notes, and snippets.

@gergelypolonkai
Created April 27, 2015 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gergelypolonkai/9c721ceda6d3079b4f05 to your computer and use it in GitHub Desktop.
Save gergelypolonkai/9c721ceda6d3079b4f05 to your computer and use it in GitHub Desktop.
Round number to N decimals
(defun get-number-at-point ()
(interactive)
(skip-chars-backward "0123456789.-")
(or (looking-at "[0123456789.-]+")
(error "No number at point"))
(string-to-number (match-string 0)))
(defun round-number-at-point-to-decimals (decimal-count)
(interactive "NDecimal count: ")
(let ((mult (expt 10 decimal-count)))
(replace-match (number-to-string
(/
(fround
(*
mult
(get-number-at-point)))
mult)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment