Replicating a string value

says that I have a string str = "45.6767676";  Now in the output I need to show as 45.67  if the string is str = "4";  then display the output as 4  is there a built-in function to do this. thanks

+2


a source to share


4 answers


double value = double.Parse(str);
Console.WriteLine(value.ToString("##.##"));

      



+3


a source


Look here: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx



0


a source


Just check if the string contains a decimal. If so, use the options provided in the link posted by Jouke. If it isn't, then don't do anything.

0


a source


Console.WriteLine(Double.Parse("4.676767").ToString("0.##"));

      

0


a source







All Articles