Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which format string to displays the float as is?

Tags:

c#

I have a float of about 27 significant figures, when I call "ToString()" I get "6.8248054E+26", how do I get the exact normal value?

like image 980
Mohamed Mokhtar Avatar asked Feb 27 '16 17:02

Mohamed Mokhtar


2 Answers

I know you want to display 27-digit significant figure and you use float. You can always do like this:

f.ToString("F27");

But really, they just don't match. Consider using decimal to achieve that precision:

decimal dc = 91.123142141230131231231M; //your 27-digit figure:
dc.ToString("F27");
like image 119
Ian Avatar answered Sep 19 '22 07:09

Ian


var number = 0.111111111100000000000000000;
string result = String.Format("{0:#,0.###########################}", number);

This would show all decimals places up to the 27th, but omits all trailing zeros. So the above number would be displayed as 0.1111111111.

like image 29
Bogey Avatar answered Sep 18 '22 07:09

Bogey