Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I convert data from string to long in c#

How could i convert data from string to long in C#?

I have data

String strValue[i] ="1100.25"; 

now i want it in

long l1; 
like image 303
MayureshP Avatar asked Jun 13 '11 12:06

MayureshP


2 Answers

If you want to get the integer part of that number you must first convert it to a floating number then cast to long.

long l1 = (long)Convert.ToDouble("1100.25"); 

You can use Math class to round up the number as you like, or just truncate...

  • Math.Round
  • Math.Ceil
like image 87
BrunoLM Avatar answered Oct 21 '22 02:10

BrunoLM


You can also use long.TryParse and long.Parse.

long l1; l1 = long.Parse("1100.25"); //or long.TryParse("1100.25", out l1); 
like image 35
majid zareei Avatar answered Oct 21 '22 03:10

majid zareei