|
-
Mar 16th, 2022, 11:25 AM
#1
[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?
My usual boring signature: Nothing
 
-
Mar 16th, 2022, 11:30 AM
#2
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.
-
Mar 16th, 2022, 11:50 AM
#3
Re: String Format Change?
 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.
-
Mar 16th, 2022, 01:36 PM
#4
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.
My usual boring signature: Nothing
 
-
Mar 22nd, 2022, 04:25 AM
#5
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
Last edited by .paul.; Mar 22nd, 2022 at 11:15 AM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|