[GB.FORM]

* NEW: Format files sizes with two decimals.

[GB.UTIL]
* BUG: File.FormatSize() now takes an optional argument that allows to 
  format the size in binary format (1K = 1024) instead of decimal format 
  (1K = 1000).


git-svn-id: svn://localhost/gambas/trunk@6718 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2014-12-11 20:59:02 +00:00
parent 3dc8d48deb
commit 5468b4c704
4 changed files with 25 additions and 13 deletions

View file

@ -1,5 +1,5 @@
# Gambas Project File 3.0 # Gambas Project File 3.0
# Compiled with Gambas 3.6.0 # Compiled with Gambas 3.6.90
Title=More controls for graphical components Title=More controls for graphical components
Startup=FDocumentView Startup=FDocumentView
Version=3.6.90 Version=3.6.90

View file

@ -45,11 +45,11 @@ Public Sub GetFileSize(iSize As Long) As String
If iSize < 1024 Then If iSize < 1024 Then
Return Subst(("&1 B"), CStr(iSize)) Return Subst(("&1 B"), CStr(iSize))
Else If iSize < 1048576 Then Else If iSize < 1048576 Then
Return Subst(("&1 KiB"), Format(iSize / 1024, "0.#")) Return Subst(("&1 KiB"), Format(iSize / 1024, "0.##"))
Else If iSize < 1073741824 Then Else If iSize < 1073741824 Then
Return Subst(("&1 MiB"), Format(iSize / 1048576, "0.#")) Return Subst(("&1 MiB"), Format(iSize / 1048576, "0.##"))
Else Else
Return Subst(("&1 GiB"), Format(iSize / 1073741824, "0.#")) Return Subst(("&1 GiB"), Format(iSize / 1073741824, "0.##"))
Endif Endif
End End

View file

@ -38,7 +38,7 @@ C
FormatSize FormatSize
M M
s s
(Size)l (Size)l[(Binary)b]
#Shell #Shell
C C

View file

@ -2,16 +2,28 @@
Export Export
Static Public Sub FormatSize(Size As Long) As String Static Public Sub FormatSize(Size As Long, Optional {Binary} As Boolean) As String
If Size < 1000 Then If {Binary} Then
Return Subst("&1 B", CStr(Size)) If Size < 1024 Then
Else If Size < 1000000 Then Return Subst(("&1 B"), CStr(Size))
Return Subst("&1 KiB", Format(Size / 1000, "#.#")) Else If Size < 1048576 Then
Else If Size < 1000000000 Then Return Subst(("&1 KiB"), Format(Size / 1024, "0.##"))
Return Subst("&1 MiB", Format(Size / 1000000, "#.#")) Else If Size < 1073741824 Then
Return Subst(("&1 MiB"), Format(Size / 1048576, "0.##"))
Else
Return Subst(("&1 GiB"), Format(Size / 1073741824, "0.##"))
Endif
Else Else
Return Subst("&1 GiB", Format(Size / 1000000000, "#.#")) If Size < 1000 Then
Return Subst(("&1 B"), CStr(Size))
Else If Size < 1000000 Then
Return Subst(("&1 KB"), Format(Size / 1000, "0.##"))
Else If Size < 1000000000 Then
Return Subst(("&1 MB"), Format(Size / 1000000, "0.##"))
Else
Return Subst(("&1 GB"), Format(Size / 1000000000, "0.##"))
Endif
Endif Endif
End End