Futureman Futureman - 1 year ago 168
ASP.NET (C#) Question

Convert double to string, keep format - C#

Hi all. I have a double number (Ex: 0.000006). I want convert it to string type. But result is "6E-06". I dont want it, i want 0.000006".Thanks you so much

double a = 0.000006;
string resultString = a.toString();

I don't know many number after "." character

Answer Source

It's simple that if you want to show a number as exactly as what it looks, we can cast it to decimal and use the default ToString() like this:

var s = ((decimal)yourNumber).ToString();
//if yourNumber = 0.00000000000000000000000006
//just append the M after it:
var s = (0.00000000000000000000000006M).ToString();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download