格式化字符串 [英] Format Strings

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

问题描述




任何人都知道为什么s等于0.0870000000000000000000以下

行执行后?


谢谢,

Nate


double d = 0.087000000000000008;

string s = string.Format(" {0:f22}",d);

解决方案

" 0870000000000000000000"长度为22


0:f# - >固定点#长度,未指定#是2我认为

如果你只想要0.87

然后只需使用0:f


Nathan Wiegman <的Na *********** @ discussions.microsoft.com>在消息中写道

news:45 ********************************** @ microsof t.com ...



任何人都知道为什么s等于0.0870000000000000000000在以下
行执行之后?

谢谢,
Nate

double d = 0.087000000000000008;
string s = string.Format(" ; {0:f22}",d);



拼写


"如果你只是想要0.87" < - 这应该是0.08

" Du" < 6 ******* @ hotmail.com>在消息中写道

新闻:IK ******************** @ rogers.com ...

" ; 0870000000000000000000"长度为22

0:f# - >固定点#长度,未指定#是2我认为

如果你只想要0.87
那么只需使用0:f

Nathan Wiegman <的Na *********** @ discussions.microsoft.com>在
消息新闻中写道:45 ********************************** @ microsof t.com。 ..



任何人都知道为什么s等于0.0870000000000000000000在以下
行执行之后?

谢谢,
Nate

double d = 0.087000000000000008;
string s = string.Format(" ; {0:f22}",d);




Nathan Wiegman写道:

任何人都知道为什么s等于0.0870000000000000000000在以下
行执行后?
double d = 0.087000000000000008;
string s = string.Format(" {0:f22}",d);




double只有15-16位精度:第17位的8位是

输了。


-

www.midnightbeach.com


Hi,

Anyone know why "s" equals "0.0870000000000000000000" after the following
lines execute?

Thanks,
Nate

double d = 0.087000000000000008;
string s = string.Format("{0:f22}", d);

解决方案

"0870000000000000000000" has length of 22

0:f# -> Fixed point with # length, unspecified # is 2 i think
if you just want 0.87
then just use 0:f

"Nathan Wiegman" <Na***********@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...

Hi,

Anyone know why "s" equals "0.0870000000000000000000" after the following
lines execute?

Thanks,
Nate

double d = 0.087000000000000008;
string s = string.Format("{0:f22}", d);



typo

"if you just want 0.87" <- this should be 0.08

"Du" <vi*******@hotmail.com> wrote in message
news:IK********************@rogers.com...

"0870000000000000000000" has length of 22

0:f# -> Fixed point with # length, unspecified # is 2 i think
if you just want 0.87
then just use 0:f

"Nathan Wiegman" <Na***********@discussions.microsoft.com> wrote in
message news:45**********************************@microsof t.com...

Hi,

Anyone know why "s" equals "0.0870000000000000000000" after the following
lines execute?

Thanks,
Nate

double d = 0.087000000000000008;
string s = string.Format("{0:f22}", d);




Nathan Wiegman wrote:

Anyone know why "s" equals "0.0870000000000000000000" after the following
lines execute? double d = 0.087000000000000008;
string s = string.Format("{0:f22}", d);



double only has "15-16 digits" precision: the 8 in the 17th place is
lost.

--

www.midnightbeach.com


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

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