在C#中不显示小数点后一位 [英] display no to one decimal place in C#

查看:109
本文介绍了在C#中不显示小数点后一位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的值为2313,546.689,2314.9.

我将这些双精度值四舍五入,但是结果显示为

2313,546.7,2314.9.

但我想要结果为

2313.0,546.7,2314.9.

表示如果no为2313,则应将其显示为2313.0,而不对其进行更改.ToString(0.0)coz我必须使用它进行过滤.

谢谢
Mohd Wasif

Hi All,

I have values as 2313 ,546.689,2314.9.

I have rounded off these double values but the result as displaying as

2313,546.7,2314.9.

but I want result as

2313.0,546.7,2314.9.

means if the no is 2313 then it should be display as 2313.0 without changing it .ToString(0.0) coz I have to use it for filtering.

Thanks
Mohd Wasif

推荐答案

尝试一下.
希望对您有帮助.
try this.
hope it will helpful for you.
int val = 28;
      string formatted = val.ToString("N1");




您可以使用CultureInfo数字格式.

检查此
Double.ToString方法(IFormatProvider) [自定义数字格式字符串 [格式设置类型 [ [
Hi,

you can go for CultureInfo Number formats.

check this
Double.ToString Method (IFormatProvider)[^]
Custom Numeric Format Strings[^]
Formatting Types[^]

For more information refer this[^]

hope it helps.


string a = (2313).ToString("0.0"); // result a=2313.0


祝您编码愉快!
:)


Happy Coding!
:)


这篇关于在C#中不显示小数点后一位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆