C# How to convert double to string with present all digitals numbers ?

dvplayltd used Ask the Experts™
      Hi experts!

  Im using C# 2008. I have a double variable which I need to convert to string. With this code it work, but last 2 digitals are truncate. I need all digital, no matter they are 2,6, 10 or more !

 Here you code
 dtDOuble = 40110.440049189812;
 dtDOuble.ToString() is  "40110.4400491898"
Look  last 2 digital are lost.

What code I need to make sure that in string I have all digitals ?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

try this dtDOuble.ToString("R")

   dtDOuble = 40110.440049189812;

The default 'ToString()' truncates on 10 digits (standard for most cultures).
Since you are working with doubles, the accurate precision is somewhat limited, but you can get a better presentation by specifying the notation you would like to use.
See http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx and http://msdn.microsoft.com/en-us/library/kfsatb94.aspx for more information.



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial