user2352554
user2352554

Reputation: 531

How to convert float or double to string

i have a variable such this

double a=123456789012345678901234567890.1234567890123456;

i want to convert a(above variable) to string value in

console.writeline();

when i write

a.ToString(); 

i see the result as

1.23456789012346E+29

but only i want to have a varable such below.

string s="123456789012345678901234567890.1234567890123456";

how can i make s from a?

Upvotes: 0

Views: 121

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 156978

You can't, since double doesn't have such a high precision you can save the entire number into the double. (To see what part is actually saved, try Console.WriteLine(a.ToString("n9"));)

You have to use another data type that does support such high precision numbers, for example BigDecimal.

Upvotes: 1

Related Questions