开发者

repalcing the string value

开发者 https://www.devze.com 2022-12-30 15:18 出处:网络
letssay i have an string str=\"45.6767676\"; now in outputi need to show as 45.67 if the stringas str= \"4\";

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


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


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


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消