- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Round-trip ("R") Format Specifier
This round-trip ("R") format specifier is supported for the Single, Double, and BigInteger types.
It ensures that a numeric value converted to a string is parsed back into the same numeric value.
Let us see an example −
Firstly, we have a double variable.
double doubleVal = 0.91234582637;
Now, use the ToString() method: and set the Round-trip format specifier.
doubleVal.ToString("R", CultureInfo.InvariantCulture);
Let us see the complete example −
Example
using System; using System.Numerics; using System.Globalization; class Demo { static void Main() { double doubleVal = 0.91234582637; string str = doubleVal.ToString("R", CultureInfo.InvariantCulture); double resRound = double.Parse(str, CultureInfo.InvariantCulture); // round-trip Double with 'R' Console.WriteLine(doubleVal.Equals(resRound)); } }
Output
True
Advertisements