如何获得花车值不包括指数符号 [英] How to get floats value without including exponential notation

查看:125
本文介绍了如何获得花车值不包括指数符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,是否有可能在一个浮动执行的ToString,并且不使用指数函数获取值

In C#, is it possible to perform ToString on a float and get the value without using exponentials?

例如,请考虑以下几点:

For example, consider the following:

float dummy;

dummy = 0.000006F;

Console.WriteLine(dummy.ToString());

这使输出

6E-06

不过,我是

0.000006



最接近我能找到用的是​​F预选赛,但是我再需要指定小数位,否则价值得到四舍五入的数量。

The closest I could find was using the "F" qualifier, however I then need to specify the number of decimal places otherwise the value get rounded.

时居然出现自动这样做的方式或做我需要做的时髦逻辑的负荷,无论是内饰零,或者找出所需的小数位数。

Is there actually a way of doing this automatically or do I need to do a load of funky logic to either trim zeroes or figure out the number of required decimals.

感谢;结果
理查德·莫斯

Thanks;
Richard Moss

推荐答案

尝试这种

Console.WriteLine(dummy.ToString("F"));

您也可以指定小数位数。例如F5,F3等。

You can also specify number of decimal places. For example F5, F3, etc.

此外,您还可以检查自定义格式说明

Also, you can check custom format specifier

Console.WriteLine(dummy.ToString("0.#########"));

这篇关于如何获得花车值不包括指数符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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