Symfony2 Doctrine CAST AS DECIMAL

Symfony2 Doctrine CAST AS DECIMAL(Symfony2 Doctrine CAST AS DECIMAL)
本文介绍了Symfony2 Doctrine CAST AS DECIMAL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Symfony2 中使用 Sonata Admin Bundle 并有一个自定义过滤器.在数据库中,列是浮动的(无法更改).如果你输入 1333.33 将没有结果.

I use Sonata Admin Bundle in Symfony2 and have a custom filter. In database, column is float (cannot change it). If you type 1333.33 there will be no result.

一种解决方案是使用 CAST:

One solution is to use CAST:

CAST( o.price AS DECIMAL) = CAST( 399.99 AS DECIMAL)

查询在 SQL 中运行良好,但 Doctrine 抛出错误.所以我的问题是如何在 Doctrine 或其他可靠的解决方案中使用 CAST?

Query is working just fine in SQL but Doctrine throws an error. So my question is how can use CAST in Doctrine or another reliable solution?

推荐答案

Doctrine 在其 DQL 中没有提供 CAST 构造(参见 这个列表).

Doctrine does not provide a CAST construct in its DQL (see this list).

但对于您的特殊情况,比较乘以 100 的值应该足够了:

But for your special case, it should be enough to compare the values multiplyed by 100:

o.price * 100 = 399.99 * 100

这篇关于Symfony2 Doctrine CAST AS DECIMAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)