在C#双格式 [英] Format double in C#

查看:106
本文介绍了在C#双格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有双重价值。我想格式化x.yz.格式这个值我该怎么做呢?我不断收到数字截断。谁能告诉我该怎么做这在C#?

I have a double value. I want to format this value in the format of x.yz. How do I do this? I keep getting digits truncated. Can someone tell me how to do this in C#?

谢谢!

推荐答案

使用格式字符串中解释:

Using format strings is explained in:

  • Standard Numeric Format Strings
  • Custom Numeric Format Strings

例如,尝试:


  • (0.56789)的ToString(F2)

  • (0.56789)的ToString(0.00)

  • (0.56789).ToString("F2")
  • (0.56789).ToString("0.00").

请注意所产生的价值不会被截断,但四舍五入在两种情况下,导致0.57

Note that the resulting value is NOT truncated, but rounded in both cases, resulting in "0.57".

这篇关于在C#双格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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