Round double in two decimal places in C#?

后端 未结 8 2155
忘掉有多难
忘掉有多难 2020-11-30 18:21

I want to round up double value in two decimal places in c# how can i do that?

double inputValue = 48.485;

after round up

i         


        
8条回答
  •  执念已碎
    2020-11-30 18:58

    Another easy way is to use ToString with a parameter. Example:

    float d = 54.9700F;    
    string s = d.ToString("N2");
    Console.WriteLine(s);
    

    Result:

    54.97
    

提交回复
热议问题