• <small id='UCZJ7'></small><noframes id='UCZJ7'>

    <i id='UCZJ7'><tr id='UCZJ7'><dt id='UCZJ7'><q id='UCZJ7'><span id='UCZJ7'><b id='UCZJ7'><form id='UCZJ7'><ins id='UCZJ7'></ins><ul id='UCZJ7'></ul><sub id='UCZJ7'></sub></form><legend id='UCZJ7'></legend><bdo id='UCZJ7'><pre id='UCZJ7'><center id='UCZJ7'></center></pre></bdo></b><th id='UCZJ7'></th></span></q></dt></tr></i><div id='UCZJ7'><tfoot id='UCZJ7'></tfoot><dl id='UCZJ7'><fieldset id='UCZJ7'></fieldset></dl></div>
    <legend id='UCZJ7'><style id='UCZJ7'><dir id='UCZJ7'><q id='UCZJ7'></q></dir></style></legend>

        <bdo id='UCZJ7'></bdo><ul id='UCZJ7'></ul>
      1. <tfoot id='UCZJ7'></tfoot>

        将双精度格式设置为两位小数

        时间:2023-09-16
          <tbody id='LnDA2'></tbody>

            <legend id='LnDA2'><style id='LnDA2'><dir id='LnDA2'><q id='LnDA2'></q></dir></style></legend>
          1. <tfoot id='LnDA2'></tfoot>

              <bdo id='LnDA2'></bdo><ul id='LnDA2'></ul>
                • <small id='LnDA2'></small><noframes id='LnDA2'>

                  <i id='LnDA2'><tr id='LnDA2'><dt id='LnDA2'><q id='LnDA2'><span id='LnDA2'><b id='LnDA2'><form id='LnDA2'><ins id='LnDA2'></ins><ul id='LnDA2'></ul><sub id='LnDA2'></sub></form><legend id='LnDA2'></legend><bdo id='LnDA2'><pre id='LnDA2'><center id='LnDA2'></center></pre></bdo></b><th id='LnDA2'></th></span></q></dt></tr></i><div id='LnDA2'><tfoot id='LnDA2'></tfoot><dl id='LnDA2'><fieldset id='LnDA2'></fieldset></dl></div>

                • 本文介绍了将双精度格式设置为两位小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在尝试将打印出来的答案精确到小数点后两位.所涉及的所有数学运算都必须保持小数点后两位的格式.我已经尝试了一些事情,但我不确定要进行哪些更改才能使这项工作正常进行.

                  I have been trying to make the answer this prints out to be to two decimal places. All the math involved has to stay at that format of two decimal places. I have tried a few things and I am not sure what to change to make this work.

                  double pdt1 = 239.99;
                  double pdt1Total;
                  double pdt2 = 129.75;
                  double pdt2Total;
                  double pdt3 = 99.95;
                  double pdt3Total;
                  double pdt4 = 350.89;
                  double pdt4Total;
                  double wage = 200;
                  double percentage = 9;
                  double total;
                  double answer;
                  double i = 100;
                  double a;
                  double b;
                  double c;
                  double d;
                  
                  
                  Console.Write("Enter number sold of product #1: ");
                  a = Convert.ToInt32(Console.ReadLine());
                  
                  Console.Write("Enter number sold of product #2: ");
                  b = Convert.ToInt32(Console.ReadLine());
                  
                  Console.Write("Enter number sold of product #3: ");
                  c = Convert.ToInt32(Console.ReadLine());
                  
                  Console.Write("Enter number sold of product #4: ");
                  d = Convert.ToInt32(Console.ReadLine());
                  
                  
                  
                  pdt1Total = a * pdt1;
                  pdt2Total = b * pdt2;
                  pdt3Total = c * pdt3;
                  pdt4Total = d * pdt4;
                  
                  total = (pdt1Total + pdt2Total + pdt3Total + pdt4Total);
                  
                  
                  
                  string.Format("{0:0.00}", total);
                  string.Format("{0:0.00}", answer = (total * percentage / i) + wage);
                  
                  
                  Console.WriteLine("Earnings this week: "+answer+"");
                  

                  推荐答案

                  string.Format 不会改变原来的值,但是会返回一个格式化的字符串.例如:

                  string.Format will not change the original value, but it will return a formatted string. For example:

                  Console.WriteLine("Earnings this week: {0:0.00}", answer);
                  

                  注意:Console.WriteLine 允许内联字符串格式.以上等价于:

                  Note: Console.WriteLine allows inline string formatting. The above is equivalent to:

                  Console.WriteLine("Earnings this week: " + string.Format("{0:0.00}", answer));
                  

                  这篇关于将双精度格式设置为两位小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何将十进制值显示到小数点后 2 位? 下一篇:如何将 DateTime 格式化为 24 小时制?

                  相关文章

                • <i id='roV9P'><tr id='roV9P'><dt id='roV9P'><q id='roV9P'><span id='roV9P'><b id='roV9P'><form id='roV9P'><ins id='roV9P'></ins><ul id='roV9P'></ul><sub id='roV9P'></sub></form><legend id='roV9P'></legend><bdo id='roV9P'><pre id='roV9P'><center id='roV9P'></center></pre></bdo></b><th id='roV9P'></th></span></q></dt></tr></i><div id='roV9P'><tfoot id='roV9P'></tfoot><dl id='roV9P'><fieldset id='roV9P'></fieldset></dl></div>
                  <legend id='roV9P'><style id='roV9P'><dir id='roV9P'><q id='roV9P'></q></dir></style></legend>
                • <small id='roV9P'></small><noframes id='roV9P'>

                      <bdo id='roV9P'></bdo><ul id='roV9P'></ul>
                      <tfoot id='roV9P'></tfoot>