与前导零的整数 [英] Integer with leading zeroes

查看:120
本文介绍了与前导零的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我写 System.out.println(0123); 我得到 83 然而 System.out.println((int)0123F); 打印 123

When I write System.out.println(0123); I get 83 however System.out.println((int)0123F); prints 123.

为什么这样做?

推荐答案

八进制(基数为8)



0123表示 octal 123,即1 * 8 * 8 + 2 * 8 + 3,等于83.
由于某种原因,八进制浮点数不可用。

Octal (base-8 number)

0123 means octal 123, that is 1*8*8 + 2*8 + 3, which equals 83. For some reason, octal floats are not available.

创建0123表示整数83.
创建0123F表示浮动123.当转换回整数时,它仍为123.

Creating 0123 means the integer 83. Creating 0123F means the floating 123. When converted back to integer, it remains 123.

只是不要使用前导0如果你不是指八进制。毕竟,它们并不完全有用(当你看到09F时,了解八进制数的程序员会感到困惑。)

Just don't use the leading 0 if you don't mean octal. After all, they are not exactly useful(and programmers who do know about octal numbers will get confused when they see 09F).

这篇关于与前导零的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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