UBinarySizeToString(String, IFormatProvider) Method
Formats the value of the current
UBinarySize instance using the specified
format.
Namespace: OokiiAssembly: Ookii.BinarySize (in Ookii.BinarySize.dll) Version: 1.2.0+20f0bdf981c7baf115c68ccab612b1a031efcb4d
public string ToString(
string? format,
IFormatProvider? formatProvider = null
)
Public Function ToString (
format As String,
Optional formatProvider As IFormatProvider = Nothing
) As String
public:
virtual String^ ToString(
String^ format,
IFormatProvider^ formatProvider = nullptr
) sealed
abstract ToString :
format : string *
?formatProvider : IFormatProvider
(* Defaults:
let _formatProvider = defaultArg formatProvider null
*)
-> string
override ToString :
format : string *
?formatProvider : IFormatProvider
(* Defaults:
let _formatProvider = defaultArg formatProvider null
*)
-> string
- format String
-
The format to use, or to use the default format.
- formatProvider IFormatProvider (Optional)
-
The provider to use to format the value, or to obtain the numeric
format information from the current locale setting of the operating system.
StringThe value of the current instance in the specified format.
IFormattableToString(String, IFormatProvider)
If format is , an empty string, or "G" (the
general format specifier), the value will be formatted using the largest binary prefix in
which it can be represented without fractions, with the suffix "iB", and a space before
the unit. For example, "2 TiB", or "512 B". It is equivalent to using " AiB".
Otherwise, the value of format must be either a multiple-byte unit by
itself, or a
standard numeric format string
or custom numeric format string
followed by a multiple-byte unit.
The multiple-byte unit can be one of the following:
Format string | Description |
---|
B |
The output will be formatted as raw bytes, with the suffix "B", e.g. "512B".
|
K[i][B], M[i][B], G[i][B], T[i][B], P[i][B], E[i][B] |
The output will be formatted as kibibytes, mebibytes, gibibytes, tebibytes, pebibytes,
or exbibytes respectively, with an optional 'i' for IEC units, and an optional 'B'.
For these units, SI prefixes without the 'i' character are treated as binary prefixes,
so 1 KB equals 1 KiB equals 1,024 bytes, and so on. For example, "1.5KiB", or "2Mi" or
"42TB".
|
k[B], m[B], g[B], t[B], p[B], e[B] |
With a lower case prefix, the output will be formatted as decimal kilobytes,
megabytes, gigabytes, terabytes, petabytes, or exabytes respectively, followed by an
optional 'B'. In this case, 1 kB equals 1,000 bytes, 1 MB equals 1,000,000 bytes, and
so on. The unit prefix will be capitalized in the output, except for "k" which should
be lower case as an SI prefix. For example, "1.5kB", or "2M" or "42TB".
|
A[i][B] |
Automatically select the largest prefix in which the value can be represented without
fractions, optionally followed by an 'i' and/or a 'B'. For example, 1,572,864 bytes
would be formatted as "1536KiB" ("AiB"), "1536Ki" ("Ai"), "1536KB" ("AB"), or "1536K"
("A").
|
a[B] |
Automatically select the largest decimal prefix in which the value can be represented without
fractions, optionally followed by a 'B'. For example, 1,500,000 bytes would be formatted
as "1500kB" ("aB"), or "1500k" ("a").
|
S[i][B] |
Automatically select the largest prefix where the value is at least 1, allowing the
use of fractional values, optionally followed by an 'i' and/or a 'B'. For example,
1,572,864 bytes would be formatted as "1.5MiB" ("SiB"), "1.5Mi" ("Si"), "1.5MB" ("SB")
or "1.5M" ("S").
|
s[B] |
Automatically select the largest decimal prefix where the value is at least 1,
allowing the use of fractional values, optionally followed by a 'B'. For
example, 1,500,000 bytes would be formatted as "1.5MB" (sB), or "1.5M" (s).
|
byte, K[i]byte, M[i]byte, G[i]byte, T[i]byte, P[i]byte, E[i]byte, A[i]byte,
S[i]byte
|
Format the output using the specified or automatic unit, using the ulong form of the
unit (e.g. "kilobytes" or "mebibytes"). IEC prefixes will be used if the 'i' is
present, and all prefixes are treated as binary prefixes.
|
kbyte, mbyte, gbyte, tbyte, pbyte, ebyte, abyte, sbyte
|
Format the output using the specified or automatic SI unit, using the ulong form of the
unit (e.g. "kilobytes" or "megabytes"), and using decimal prefixes.
|
Any of the above multi-byte units may follow a numeric format string; for example,
"#,##0.# SiB".
If a multi-byte unit is surrounded by white space, this will be preserved in the output.
For example, " KB" can be used to format the value 512 as "0.5 KB".
Since "G" by itself is the general format specifier, it cannot be used to format as
gibibytes; use "GG" instead for this purpose. Using " G" with leading white space or a
number format will work correctly.
The actual units used when formatting are determined by the BinaryUnitInfo
object provided by the formatProvider, or the value of the
BinaryUnitInfoInvariantInfo property if the provider
doesn't support this type.
The properties defining abbreviated units, such as BinaryUnitInfoShortByte,
BinaryUnitInfoShortKibi or BinaryUnitInfoShortKilo
are used for all format strings, except those that end in "byte", which use the
full units, defined by properties such as BinaryUnitInfoLongByte,
BinaryUnitInfoLongKibi or BinaryUnitInfoLongKilo.
The BinaryUnitInfoShortByte and BinaryUnitInfoLongByte
property are only used if the value, when scaled to the prefix, is exactly one. For
example, 1 B, 1 KiB, 1 PB, etc. Otherwise, the BinaryUnitInfoShortBytes
and BinaryUnitInfoLongBytes properties are used, which
provide the plural versions. For the abbreviated units in the default, English-language
version, these values are the same (both "B"), but for the full units they are different
("byte" and "bytes").
If the value is not exactly one, but is rounded to one by the number format used, the
BinaryUnitInfoLongByte and
BinaryUnitInfoLongBytes properties are still used.
For example, a value of 1.01 kibibytes, when using a format string of "0.# Sibyte", would be
formatted as "1 kibibytes", using the plural version of the unit.