简体   繁体   中英

Display double value without scientific notation

I have a null able double value which get values from data base.It retrieve value from data base as '1E-08'. I want to display the value with out scientific notification (0.00000001)

I used the following code.

double? valueFromDB=1E-08;
string doubleValue=valueFromDB.Value.Value.ToString();
string formatedString=String.Format("{0:N30}", doubleValue);

But the value of formatedString is still 1E-08.

You're calling string.Format with a string . That's not going to apply numeric formatting. Try removing the second line:

double? valueFromDB = 1E-08;
string formattedString = String.Format("{0:N30}", valueFromDB.Value);

Or alternatively, specify the format string in a call to ToString on the value:

double? valueFromDB = 1E-08;
string formattedString = valueFromDB.Value.ToString("N30");

That produces 0.000000010000000000000000000000 for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM