Reputation: 7777
lets say i have an string str="45.6767676"; now in output i need to show as 45.67 if the string as str= "4"; then show the output as 4 is there any built in function to do this. thanks
Upvotes: 2
Views: 108
Reputation: 5600
Just check if the string contains a decimal. If it does, then make use of the options provided in the link posted by Jouke. If it does not, then don't do anything.
Upvotes: 0
Reputation: 6585
double value = double.Parse(str);
Console.WriteLine(value.ToString("##.##"));
Upvotes: 3
Reputation: 4328
See here: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
Upvotes: 0