From fcc4070cc088e342f1df01bc1fe7acb1be6186ff Mon Sep 17 00:00:00 2001 From: cage Date: Fri, 4 Feb 2022 12:37:41 +0100 Subject: [PATCH] - improved 'fs:octects->units-string'. --- src/filesystem-utils.lisp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/filesystem-utils.lisp b/src/filesystem-utils.lisp index eaff7bf..8e2d8bd 100644 --- a/src/filesystem-utils.lisp +++ b/src/filesystem-utils.lisp @@ -544,20 +544,17 @@ (format nil (config:_ "invalid value: ~a") object)) (defmethod octects->units-string ((object number)) - (let ((decimals (loop - for number = object then (truncate (/ number 10)) while (> number 0) - for results = 0 then (1+ results) - finally (return results)))) + (let ((decimals (1- (num-utils:count-digit object)))) (cond ((or (null decimals) - (<= decimals 3)) + (< decimals 3)) (format nil (config:_ "~a bytes") object)) - ((<= 4 decimals 6) - (format nil (config:_ "~a Kib") (truncate (octects->units object :kib)))) - ((<= 7 decimals 9) - (format nil (config:_ "~a Mib") (truncate (octects->units object :mib)))) + ((<= 3 decimals 5) + (format nil (config:_ "~,1f Kib") (octects->units object :kib))) + ((<= 6 decimals 8) + (format nil (config:_ "~,1f Mib") (octects->units object :mib))) (t - (format nil (config:_ "~a Gib") (truncate (octects->units object :gib))))))) + (format nil (config:_ "~,1f Gib") (octects->units object :gib)))))) (defgeneric normalize-path (object))