相关疑难解决方法(0)

删除尾随零

我有一些集合返回的字段为

2.4200
2.0044
2.0000
Run Code Online (Sandbox Code Playgroud)

我想得到的结果

2.42
2.0044
2
Run Code Online (Sandbox Code Playgroud)

我尝试过String.Format,但它返回2.0000并将其设置为N0舍入其他值.

.net c# decimal

160
推荐指数
7
解决办法
13万
查看次数

如何在没有科学记数法或尾随零的情况下输出float到cout?

在C++中输出浮点数的最优雅方法是什么,没有科学记数法或尾随零?

float a = 0.000001f;
float b = 0.1f;

cout << "a: " << a << endl;     //  1e-006 terrible, don't want sci notation.
cout << "b: " << b << endl;     //  0.1 ok.

cout << fixed << setprecision(6);
cout << "a: " << a << endl;     //  0.000001 ok.
cout << "b: " << b << endl;     //  0.100000 terrible, don't want trailing zeros.
Run Code Online (Sandbox Code Playgroud)

c++

7
推荐指数
1
解决办法
4031
查看次数

标签 统计

.net ×1

c# ×1

c++ ×1

decimal ×1