In .NET, how can I convert from "0.000" to a 'long'?
Posted
by willem
on Stack Overflow
See other posts from Stack Overflow
or by willem
Published on 2010-06-08T11:41:53Z
Indexed on
2010/06/08
11:52 UTC
Read the original article
Hit count: 127
I have a string, "0.000" (or any similar string), that I would like to convert to a long. I am happy to "chop-off" anything after the decimal.
What is the best way to go about this?
I can convert to double and then to long, but I'm just wondering if there is an easier way. All the following statements throw exceptions:
long l3 = Convert.ToInt64(nrToConvert);
long l1;
long.TryParse(nrToConvert, out l1);
long l2 = long.Parse(nrToConvert);
© Stack Overflow or respective owner