I got a question that converting string data type to double.
For instance, I want to get maintain decimal 2 places of 573 so I did
string a = Math.Round(573, 2).ToString(“F2”);
However, I need the data type as “double”, so I used “Convert.ToDouble(a)” method .
double b = Convert.ToDouble(a);
It turns out that it removes the decimals 2 places that I want to keep.
I 'd like to knows how to maintain the decimal places and return a double data type.
Wait, this doesn’t make sense. The number is the number, no matter how many zeros it has. What you’re interested in is how you convert it to text for display, what’s the problem you have? You have ways to print it with 2 decimals.
I use a function that returns a double, and it sometimes doesn’t have decimals.
The problem I have is that I need the result that always keeps 2 (or flexible) decimal places and it has to be a “double” data type.