If I wanted to convert a double to a string and back to a double that matches exactly, I would use something like:
double d1 = 1 / 3.0;
string s = d1.ToString("R");
double d2 = double.Parse(s);
But, the "R" format isn't defined for a decimal type (you get a "FormatException: Format specifier was invalid").
What is the way to produce a round-trip string for a decimal type?
The default output format for decimal
round-trips, so you don't have to do anything special. It is just like int
in that sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With