Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 337
Futureman Avatar asked May 17 '26 03:05

Futureman


1 Answers

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();
like image 123
King King Avatar answered May 19 '26 17:05

King King