From adf5f3943970161b0476fe31718828b495c639cb Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 6 Oct 2014 10:30:20 +0200 Subject: [PATCH] Add round-number-to-decimal.el --- init.el | 1 + round-number-to-decimals.el | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 round-number-to-decimals.el diff --git a/init.el b/init.el index 799e803..9d62d6b 100644 --- a/init.el +++ b/init.el @@ -63,6 +63,7 @@ (load "gnu-c-header.el") (load "gobgen/gobgen.el") (load "toggle-window-split.el") +(load "round-number-to-decimals.el") (add-hook 'c-mode-hook 'helm-gtags-mode) (add-hook 'c-mode-hook 'which-func-mode) diff --git a/round-number-to-decimals.el b/round-number-to-decimals.el new file mode 100644 index 0000000..cb4ec86 --- /dev/null +++ b/round-number-to-decimals.el @@ -0,0 +1,19 @@ +(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))))) + +(global-set-key (kbd "C-c r") 'round-number-at-point-to-decimals)