Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Produce a round-trip string for a decimal type

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?

like image 646
mheyman Avatar asked Jan 23 '14 14:01

mheyman


1 Answers

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.

like image 190
Gabe Avatar answered Sep 17 '22 06:09

Gabe