C# 将双精度转换为字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/533931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 07:08:01  来源:igfitidea点击:

Convert double to string

c#typeconverter

提问by Kartik

i have three double variable a ,b and c

我有三个双变量 a ,b 和 c

a = 0.000006 
b = 6 
c = a/b;

so C should be 0.000001

所以 C 应该是 0.000001

i want to show this value in text box so i wrote

我想在文本框中显示这个值所以我写了

textbox.text = c.tostring();

but it's give result as "1E-06"..

但它的结果是“1E-06”..

Can anybody help me out how can i put correct value in textbox ?

任何人都可以帮助我如何在文本框中输入正确的值?

Thanks

谢谢

采纳答案by Adam Davis

a = 0.000006;
b = 6;
c = a/b;

textbox.Text = c.ToString("0.000000");

As you requested:

按照您的要求:

textbox.Text = c.ToString("0.######");

This will only display out to the 6th decimal place if there are 6 decimals to display.

如果要显示 6 位小数,这只会显示到第 6 位小数。

回答by Jim Arnold

Try c.ToString("F6");

尝试 c.ToString("F6");

(For a full explanation of numeric formatting, see MSDN)

(有关数字格式的完整说明,请参阅MSDN