为什么YAML.load返回错误的数值? [英] Why is YAML.load returning the wrong numeric value?

查看:223
本文介绍了为什么YAML.load返回错误的数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么YAML.load返回错误的值?

Why is YAML.load returning the wrong value?

ruby-1.9.2-p0 :006 > a = YAML.load('merchant_id: 014213245611111')
 => {"merchant_id"=>843333440073} 
ruby-1.9.2-p0 :007 > a["merchant_id"]
 => 843333440073 

我正在使用ruby 1.9.2-p0,rvm,ubuntu10.10、64位.

I'm on ruby 1.9.2-p0, rvm, ubuntu10.10, 64bit.

推荐答案

YAML解析器将"014213245611111"视为八进制(以8为底)数字,而不是字符串.将其用引号引起来,以保留前导0.

The YAML parser is treating "014213245611111" as an octal (base-8) number, rather than a string. Wrap it in quotes to preserve the leading 0.

这篇关于为什么YAML.load返回错误的数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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