教义2,小数只能包含14位数 [英] Doctrine 2, decimal can only contain 14 digits

查看:129
本文介绍了教义2,小数只能包含14位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:这只是被确认为在Doctrine 2
http://www.doctrine-project.org/jira/browse/DDC-1112?page=com.atlassian。 jira.plugin.system.issuetabpanels:comment-tabpanel& focusedCommentId = 15724#action_15724

This was just confirmed as a bug in Doctrine 2 http://www.doctrine-project.org/jira/browse/DDC-1112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15724#action_15724

我有一个Doctrine 2实体和值被映射成这样(通常是getter / setter):

I have a Doctrine 2 entity and the value is mapped like this (with regular getter/setter):

/**
 * @Column(type="decimal", precision=40, scale=30)
 */
protected $someValue;

/**
 * @return decimal
 */
public function getSomeValue()
{
    return $this->someValue;
}

/**
 * @param decimal $someValue
 */
public function setSomeValue($someValue)
{
    $this->someValue = $someValue;
}

当我从代码中设置该值时,该值将被写入数据库正确。但是,这是我的问题,当我获取值(通过getter或 \Doctrine\Common\Util\Debug :: dump()),它总是给我一个最多14位数的数字,并且它的数值。我读了默认的 findById()的记录。

When I set that value from my code, the value gets written into the database correctly. But, and that is my problem, when I get the value (via getter or \Doctrine\Common\Util\Debug::dump()), it always gives me a number with maximum 14 digits, and it rounds the value. I read the record with the default findById().

eg: with value 1234567890.012345678901234567890123456789 I have 1234567890.0123
eg: with value 890.0123456789012345678901234567890123456 I have 890.01234567890

我当然希望所有数字,而不只是14. MySQL中的字段声明如下:

I of course want all digits, not just 14. The field in MySQL is declared like this:

someValue decimal(40,30)NOT NULL,

当我获取原始PHP和mysql_query()的值时,它将正确返回。

When I get the value with raw PHP and mysql_query(), it returns correctly.

编辑:似乎问题是Doctrine返回一个float:

Edit: seems like the problem is that Doctrine returns a float:

["someValue":protected]=> float(234567890.01235)

有什么问题,下一步应该怎么检查,如何修复任何线索? / p>

What's wrong, what should I check next, how to fix, any clues?

推荐答案

听起来Doctrine2正在返回float值并运行到浮点精度,而 mysql_query()将该值作为字符串返回。您可以在每个返回的变量上执行 var_dump(),并查看标量类型。

It sounds like Doctrine2 is returning the float value and is running into floating point precision while mysql_query() is returning the value as a string. You can do a var_dump() on each returned variable and see the scalar type.

这篇关于教义2,小数只能包含14位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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