c# - 转换为字符串时精度下降到 3 位大数字

标签 c#

我有以下类型的 double

var a_number = 105229626666.6667;

当我存储它或将其转换为字符串时,数字会自动截断为小数点后 3 位,而不是“105229626666.667”。

有没有办法规避这个问题?

Screenshot

最佳答案

试试这个:

number.ToString("R");

R 代表“往返”:

This format is supported only for the Single and Double types. The round-trip specifier guarantees that a numeric value converted to a string will be parsed back into the same numeric value.

参见 standard numeric format了解更多信息

关于c# - 转换为字符串时精度下降到 3 位大数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68096851/

相关文章:

c# - 可以从 javascript/jquery 获取返回 url 吗?

c# - 搜索列表并根据匹配的索引值获取项目

c# - LINQ 性能与 Dictionary<K,V>

c# - Azure WCF 服务无法连接到 SQL Azure

c# - 将数据插入到与外键链接的表中

c# - 使用 mongodb c# 驱动程序的本地化模式

c# - 非空值的空异常

c# - 输出 html 的 WPF 应用程序

c# - 如何在 ASP.NET WebAPI 中返回文件 (FileContentResult)

c# - 如何在 LINQ 中重新映射属性?