Last active
August 29, 2015 14:06
-
-
Save youz/423a5730dc7fb9951ef4 to your computer and use it in GitHub Desktop.
format-byte-size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; ref. http://msdn.microsoft.com/en-us/library/windows/desktop/bb759975(v=vs.85).aspx | |
(defun format-byte-size (n) | |
(labels ((rec (n units) | |
(cond ((null units)) | |
((< n 10) | |
(format nil "~,2f~a" n (car units))) | |
((< n 100) | |
(format nil "~2,1f~a" n (car units))) | |
((< n 1000) | |
(format nil "~d~a" (floor n) (car units))) | |
(t | |
(rec (/ n 1024) (cdr units)))))) | |
(rec n '("" Ki Mi Gi Ti Pi Ei Zi Yi)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
StrFormatByteSizeA を使った場合