Visual Basic.Net® ToString
Home Page
This Progr.
Trignom. 2
 Other Sites
Hit Counter 138
Open Data © the credited
Email address bouncer

Some pages may contain inaccuracies.
It is possible to convert a number to a string by appending .ToString() to the number.
Number To String
Extended Number To String
However, you can also add special characters to .ToString("") for additional features. An example of this is teh character "0", this forces numbers to have a minimum number of digits (before or after the decimal point) adding leading/triling zeros when required The value in s would be "012.3400" because the "000.0000" forces 3 digits before the decimal point and 4 digiits after the decimal point. Here are some of the "characters" which can be used to modifidy how .ToString works.
Dates and Times
(Examples use Thursday 1st July 2021 and 17:08:09)
Note -* .Net will give unexpected results or run-time errors when it encounters .ToString modifiers that are exactly 1 character in length. This is rarely experienced in normal usage because the multiple characters are usually used in combination e.g. .ToString("dd/MM/yyyy") or .ToString("hh:mm:ss").
This is because 1 character .ToString modifiers are assumed to be special format codes (described later.)
If you wish to force .NET to accept a 1 character modifier, there is a workaround. Add a space to the modifier (to make it more than 1 character long) then use .Trim to remove the space from the result. i.e
.ToString("h")   would be replaced by   .ToString("h ").Trim
You should not encounter this problem with empty modifiers or modifiers with more than one character. Special Format Codes
Examples use -1234.56789 {modifiers not case sensitive}
Additional Integer Modifiers
The code functions on this site are only intended as a learning aid. Data validation is often ommited to assist users unfamiliar with Visual Basic. The information may be untested, unreliable or unsuitable for your requirements. It is presented in a non-commercial form as an ex-gratia attempt to be helpful. By making any use of information contained on these pages, you agree to fully absolve and indemnify DigitalDan in relation to any issue arising out of such use.