(十进制)1.1对1.1M [英] (decimal) 1.1 versus 1.1M

查看:122
本文介绍了(十进制)1.1对1.1M的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



十进制d;


d = 1.1M





d =(十进制)1.1


Discussioon


M后缀看起来像是从C语言中占据的东西。不是什么?b $ b不言自明的是它是什么。我听说一位讲师说这意味着钱。

错误。


d =(十进制)1.1是自我记录。


是否有一些标准表明哪种代码最好?


Paul S.


decimal d;

d = 1.1M

OR

d= (decimal) 1.1

Discussioon

That ''M'' suffix looks like something ledt over from C. It is not
self-evident what it is. I heard one lecturer say it means money.
WRONG.

d = (decimal) 1.1 is self documenting.

Is there some standard that indicates which is the best way to code??

Paul S.

推荐答案

1.1M表示1.1是十进制值。

类似于1.1f(浮点值)。因此,不需要将其存储在

十进制变量中。


只是1.1 - 我相信是一个双精度值,必须将其转换为十进制。


-

Adam Clauss
ca * **** @ tamu.edu


Paul Sullivan < PA ********************* @ worldnet.att.net>在消息中写道

news:8c ******************************** @ 4ax.com ...
1.1M says that the 1.1 is a decimal value.
Similar to 1.1f (float value). Thus no casting is required to store it in a
decimal variable.

Just 1.1 - I believe is a double value, which has to be casted to decimal.

--
Adam Clauss
ca*****@tamu.edu

"Paul Sullivan" <pa*********************@worldnet.att.net> wrote in message
news:8c********************************@4ax.com...

十进制d;

d = 1.1M



d =(十进制)1.1

讨论

那个M后缀看起来像C语言中的一些东西。它不是不言而喻的。我听说一位讲师说这意味着金钱。
错误。

d =(十进制)1.1是自我记录。

是否有一些标准表明哪个是最好的代码方式??

Paul S。

decimal d;

d = 1.1M

OR

d= (decimal) 1.1

Discussioon

That ''M'' suffix looks like something ledt over from C. It is not
self-evident what it is. I heard one lecturer say it means money.
WRONG.

d = (decimal) 1.1 is self documenting.

Is there some standard that indicates which is the best way to code??

Paul S.



我没有检查但是我希望优化器会为两者生成相同的

代码。如果它没有,则表达式

d = 1.1M;

将产生更高效的代码,因为常量将存储为

十进制。


使用

d =(十进制)1.1;

将使常量存储为double并且使用时转换为十进制

.


就像我说的:我没有检查优化器是否处理这个问题。 />
希望如此。如果确实如此,那就没有效果了。


-

---尼克马利克[微软]

MCSD ,CFPS,认证Scrummaster
http://blogs.msdn.com/nickmalik


免责声明:在这个论坛上发表的意见是我自己的,而不是我雇主的b $ b代表。

我做的不代表我的雇主回答问题。我只是一个帮助程序员的
程序员。

-

" Paul Sullivan" < PA ********************* @ worldnet.att.net>在消息中写道

news:8c ******************************** @ 4ax.com ...
I haven''t checked but I would hope that the optimizer would produce the same
code for both. If it doesn''t, then the expression
d = 1.1M;
will produce more efficient code, since the constant will be stored as a
decimal.

Using
d = (decimal) 1.1;
will cause the constant to be stored as a double and converted to decimal
when it is used.

Like I said: I haven''t checked if the optimizer takes care of this or not.
Hope so. If it does, then there is no effective difference.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I''m just a
programmer helping programmers.
--
"Paul Sullivan" <pa*********************@worldnet.att.net> wrote in message
news:8c********************************@4ax.com...

十进制d;

d = 1.1M



d =(十进制)1.1

讨论

那个M后缀看起来像C语言中的一些东西。它不是不言而喻的。我听说一位讲师说这意味着金钱。
错误。

d =(十进制)1.1是自我记录。

是否有一些标准表明哪个是最好的代码方法??

Paul S。

decimal d;

d = 1.1M

OR

d= (decimal) 1.1

Discussioon

That ''M'' suffix looks like something ledt over from C. It is not
self-evident what it is. I heard one lecturer say it means money.
WRONG.

d = (decimal) 1.1 is self documenting.

Is there some standard that indicates which is the best way to code??

Paul S.



我认为代码会有所不同,具体取决于是否

1.1可以用双精确表示。请记住


double d = 1.1;


并不保证d恰好等于1.1。它将等于值为1.1的浮点表示中可用的最近似值

。我认为这就意味着


十进制e =(十进制)1.1;


意味着e应设置为最佳逼近双值

值,这是双格式1.1的最佳近似值。在

其他的话


十进制e =(十进制)1.1;

if(e == 1.1M)...

在我看来,
不保证if

语句的目标将会执行。


当然,我很容易被证明错了。 :)

I would think that the code would be different, depending upon whether
1.1 can be exactly represented in a double. Remember that

double d = 1.1;

does not guarantee that d will equal exactly 1.1. It will equal the
closest approximation available in the floating point representation
for the value 1.1. I would think that this would then mean that

decimal e = (decimal)1.1;

would mean that e should be set to the best approximation of the double
value, which is the best approximation of 1.1 in double format. In
other words

decimal e = (decimal)1.1;
if (e == 1.1M) ...

does not, in my opinion, guarantee that the target of the "if"
statement will execute.

Of course, I''m open to being shown wrong. :)


这篇关于(十进制)1.1对1.1M的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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