[英]What is the meaning of this Decimal representation in ruby?
数字是这样的:
#<BigDecimal:9829250,'0.202499E4',18(27)>
如果我打印它,它是: 2024.99
。 9829250
(也许是内存地址?)和18(27)
什么意思?
当我们有BigDecimal#inspect的文档时,无需猜测!
BigDecimal#inspect()
返回有关值的调试信息,以尖括号括起来的尖括号中的逗号分隔值的字符串形式:
BigDecimal.new("1234.5678").inspect #=> "#<BigDecimal:b7ea1130,'0.12345678E4',8(12)>"
第一部分是地址,第二部分是字符串形式的值,最后一部分ss(mm)分别是当前有效数字位数和最大有效数字位数。
如果您已安装源,则可以在那里查看。 以下信息适用于RVM的本地用户安装。
作为@Dogbert答案的替代方法,您还可以检出源文件:
cd ~/.rvm/src/ruby-2.2.4/ext/bigdecimal/
如果您在2034行附近查看bigdecimal.c
,则会看到文档:
/* Returns debugging information about the value as a string of comma-separated
* values in angle brackets with a leading #:
*
* BigDecimal.new("1234.5678").inspect ->
* "#<BigDecimal:b7ea1130,'0.12345678E4',8(12)>"
*
* The first part is the address, the second is the value as a string, and
* the final part ss(mm) is the current number of significant digits and the
* maximum number of significant digits, respectively.
*/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.