Math.Round vs String.Format

前端 未结 6 1773
天命终不由人
天命终不由人 2021-01-18 18:24

I need double value to be rounded to 2 digits. What is preferrable?

String.Format(\"{0:0.00}\", 123.4567);      // \"123.46\"
Math.Round(123.4567, 2)                 


        
6条回答
  •  长发绾君心
    2021-01-18 18:59

    Math.Round will not add any decimal places if there aren't any to begin with. String.Format will. e.g.: Math.Round(2) returns 2; String.Format("{0:0.00}",2) returns 2.00;

提交回复
热议问题