浮点文字,浮点文字,双字面量 [英] Floating point literal, floating literal, double Literal

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

问题描述

在Java中,浮点文字"和浮点文字"是同一东西吗?

Is the 'floating point literal' and the 'floating literal' the same thing in Java?

还有,Java中有什么叫做双文字"?

Also, is there anything called 'double literal' in Java?

推荐答案

浮点文字"是指任何浮点类型的文字. float double 都是浮点类型.

"Floating point literal" refers to any literal of a floating-point type. Both float and double are floating-point types.

我以前从未遇到过浮点文字"一词​​,但我想其预期的含义与浮点文字"相同.您应该确保要求进行澄清,,因为如果作者打算说"floatliteral",那么这将特别是 float 类型的文字.通常是任何浮点类型.

I have never come across the term "floating literal" before, but I would presume the intended meaning is the same as "floating point literal." You should make sure to ask for clarification though, because if the author intended to say "float literal" then that would be a literal of type float in particular, and not just any floating-point type in general.

对于Java中浮点文字的特定类型,所有常规形式#.#的文字都是 double ,除非您附加 f F (相同)来代替原义,以使其强制为 float .

As for the specific type of floating-point literals in Java, all literals of the general form #.# are double, unless you append f or F (same difference) to the literal to force it to be float instead.

原始数据类型上查看教程页面.甲骨文.我已经在下面复制了标题为浮点文字"的小节.

Check out the tutorial page on Primitive Data Types by Oracle. I've copied the sub-section titled "Floating-Point Literals" below.

浮点文字

如果浮点文字以字母F结尾,则其类型为float或f;否则,其类型为double,并且可以选择以字母D或d.

Floating-Point Literals

A floating-point literal is of type float if it ends with the letter F or f; otherwise its type is double and it can optionally end with the letter D or d.

浮点类型(float和double)也可以表示使用E或e(用于科学计数法),F或f(32位浮点文字)和D或d(64位双字面量;这是默认值,由约定被省略).

The floating point types (float and double) can also be expressed using E or e (for scientific notation), F or f (32-bit float literal) and D or d (64-bit double literal; this is the default and by convention is omitted).

double d1 = 123.4;
// same value as d1, but in scientific notation
double d2 = 1.234e2;
float f1  = 123.4f;

正如@Bubletan在对问题的评论中提到的那样,如果您真的很好奇,可以查看有关浮点字面量的实际Java规范:

And as @Bubletan mentioned in comment to your question, if you're really curious you could check out the actual Java specification for float-point literals: §3.10.2. Floating-Point Literals

float 文字的示例:

1e1f    2.f    .3f    0f    3.14f    6.022137e+23f

double 文字的示例:

1e1    2.    .3    0.0    3.14    1e-9d    1e137

这篇关于浮点文字,浮点文字,双字面量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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