Format Extensions
Capitalize First
This line calls the FormatToCapitalizeFirstLetter extension method to capitalize the first letter of originalString. The result is logged for verification.
string originalString = "hello world";
string formattedString = originalString.CapitalizeFirst();
Debug.Log("Formatted String: " + formattedString);
Format to Kilo
This example demonstrates how to format a float value, score, into a human-readable string with a "K" or "M" suffix, depending on its size. The formatted score is logged for reference. (1,000 to 1K, 1,000,000 to 1M)
float score = 1250f;
string formattedScore = score.FormatToKilo();
Debug.Log("Formatted Score: " + formattedScore);
Format to Percentage
This line calls the FormatToPercentage method to convert the ratio into a percentage format. The formatted percentage is logged for clarity.
float ratio = 0.85f;
string formattedRatio = ratio.FormatToPercentage();
Debug.Log("Formatted Ratio: " + formattedRatio);
Format with Separator
This example shows how to format a large float value with thousands separators for better readability. The result is logged for inspection.
float largeNumber = 1234567.89f;
string formattedNumber = largeNumber.FormatWithSeparator();
Debug.Log("Formatted Number: " + formattedNumber);
Format to Minutes and Seconds
This code formats the timeInSeconds into a string representing minutes and seconds. The result is logged for clarity, showing how the time is structured.
float timeInSeconds = 75f;
string formattedTime = timeInSeconds.FormatToTMinuteSecond();
Debug.Log("Formatted Time (MM:SS): " + formattedTime);
Format to Hours, Minutes, and Seconds
This code formats the timeInSeconds into a string representing minutes and seconds. The result is logged for clarity, showing how the time is structured.
float totalTimeInSeconds = 3661f;
string formattedFullTime = totalTimeInSeconds.FormatToHourMinuteSecond();
Debug.Log("Formatted Full Time (HH:MM:SS): " + formattedFullTime);
Format to Currency
This line formats a float value as currency using the FormatToCurrency method. The resulting string is logged to show how the currency appears.
float currencyValue = 1234.56f;
string formattedCurrency = currencyValue.FormatToCurrency();
Debug.Log("Formatted Currency: " + formattedCurrency);
Format to Bytes
This code demonstrates how to format a byte size value into a string with appropriate units (B, KB, MB, GB). The formatted size is logged for reference.
float byteSize = 1048576f;
string formattedSize = byteSize.FormatToBytes();
Debug.Log("Formatted Size: " + formattedSize);
Last updated