版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xushaozhang/article/details/78226760
1.判定小数点:
string result = midvalue % 1 == 0 ? 整数:小数
2.格式化字符,是小数的保留两位小数,是整数的直接输出;超过三位使用逗号分隔符
string result = midvalue % 1 == 0 ? string.Format("{0:N0}", midvalue) : string.Format("{0:N2}", midvalue))