简体   繁体   English

如何在C#中的double类型的条件下获取零值的十进制值

[英]How to get decimal values with zero on adiition of double type in c#

Here below is the operations.. 以下是操作。

double d=4.0;
double dd=4.0;
double results=d+dd;

it gives at the time of execution 它在执行时给出

results => 8

Instead of 代替

results => 8.0

I would like to get output like below 我想得到如下输出

results => 8.0

Will anybody tell me how to get decimal value with zero's also 有人能告诉我如何也得到零的十进制值吗

You can use String format for desired output. 您可以将String格式用于所需的输出。 like 喜欢

    String.Format(((Math.Round(results) == results) ? "{0:0}" : "{0:0.00}"), results);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM