什么是非法八进制数? [英] What is an Illegal octal digit?

查看:278
本文介绍了什么是非法八进制数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一组​​邮政编码.

I'm trying to make an array of zip codes.

array = [07001, 07920]

返回:

array = [07001, 07920]
                  ^
    from (irb):12
    from :0

以前从未见过这个.有什么解决方法吗?

Never seen this before. Any workarounds?

推荐答案

Ruby 将前导 0 的数字解释为八进制(以 8 为底).因此数字 8 和 9 无效.

Ruby is interpreting numbers that have a leading 0 as being in octal (base 8). Thus the digits 8 and 9 are not valid.

将邮政编码存储为字符串而不是数字可能更有意义(以避免在显示时必须用零填充),例如:array = ["07001", "07920"]

It probably makes more sense to store ZIP codes as strings, instead of as numbers (to avoid having to pad with zeroes whenever you display it), as such: array = ["07001", "07920"]

这篇关于什么是非法八进制数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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