开发者

Format the output of a string

开发者 https://www.devze.com 2022-12-30 10:25 出处:网络
here string strScore=\"2\"; or string strScore=\"2.45656\" now here i am checking the开发者_如何学Go condition if it is

here string strScore="2"; or string strScore="2.45656" now here i am checking the开发者_如何学Go condition if it is

 double value = double.Parse(strScore);

strScore = value.ToString("##.##");

2.45656 like this then i am showing the output as 2.45

if the input is string strScore="2"; then the ouput is shown as "2"

but now i need to show the output has 2.00 how can i format the code like this based on the condition


Try this instead:

strScore = value.ToString("0.00");

The # means that the digit is optional and leading/trailing zeros will not be displayed. If you write 0 then the digit is not optional: leading and trailing zeros will be displayed.

0

精彩评论

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