[RESOLVED] String Format Change?
According to the documentation seen here:
https://docs.microsoft.com/en-us/dot...format-strings
a string format of "D2" looks like it should be a decimal with two digits to the right of the decimal place...or something, anyways. However, "D2" results in an invalid format specifier exception, these days.
I'm pretty sure it WAS working, but I've now had two programs fail because of this. Can anybody say when or why this changed?
Re: String Format Change?
D2 is supported by integral types only. So for example:
Code:
Dim value1 As Integer = 123456789
Console.WriteLine(value1.ToString("D2")) ' works
Dim value2 As Decimal = 1.23456789
Console.WriteLine(value2.ToString("D2")) ' fails
In the words of Obi-Wan Kenobi, these aren't the droids you're looking for.
You actually want to use N2.
Re: String Format Change?
Quote:
Originally Posted by
Shaggy Hiker
According to the documentation seen here:
https://docs.microsoft.com/en-us/dot...format-strings
a string format of "D2" looks like it should be a decimal with two digits to the right of the decimal place...or something, anyways. However, "D2" results in an invalid format specifier exception, these days.
I'm pretty sure it WAS working, but I've now had two programs fail because of this. Can anybody say when or why this changed?
Decimal format specifier (D)
The "D" (or decimal) format specifier converts a number to a string of decimal digits (0-9), prefixed by a minus sign if the number is negative. This format is supported only for integral types.
The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier. If no precision specifier is specified, the default is the minimum value required to represent the integer without leading zeros.
Re: String Format Change?
HAHAHAHA!!
I read the documentation wrong. I actually have been using N for a long time, and ended up misreading D...twice.
Re: [RESOLVED] String Format Change?
You’re using the type specifier D. You could use C2 for currency, N2 (1,000,000.75 etc), or F2 (1000000.75 etc)…
Code:
Dim decimalVariable As decimal = 2.5D