; ; iron_humanize.hsp — 人間にやさしい書式変換 ; #ifndef __iron_humanize_hsp__ #define __iron_humanize_hsp__ #module iron_humanize #defcfunc humanize_bytes int bytes if bytes < 1024 : return "" + bytes + " B" if bytes < 1048576 : return strf("%.1f KB", double(bytes) / 1024.0) if bytes < 1073741824 : return strf("%.1f MB", double(bytes) / 1048576.0) return strf("%.2f GB", double(bytes) / 1073741824.0) #defcfunc humanize_seconds int sec if sec < 60 : return "" + sec + " sec" if sec < 3600 : return "" + (sec / 60) + " min " + (sec \ 60) + " sec" if sec < 86400 : return "" + (sec / 3600) + " hr " + ((sec \ 3600) / 60) + " min" return "" + (sec / 86400) + " days " + ((sec \ 86400) / 3600) + " hr" #defcfunc humanize_number int n, local s, local r, local i s = "" + n r = "" repeat strlen(s) i = strlen(s) - 1 - cnt if cnt > 0 & (cnt \ 3) == 0 : r = "," + r r = strmid(s, i, 1) + r loop return r #defcfunc humanize_percent int value, int total if total == 0 : return "0%" return strf("%.1f%%", double(value) / double(total) * 100.0) #global #endif