删除symfony上float数据类型中的额外小数位?

时间:2011-07-11 13:26:59

标签: php symfony1 symfony-1.4

我的数据库中有ff。浮:

1
1.5
1.7
2

我需要保持这个在程序中,但不知何故symfony默认自动将这些转换为ff:

1.00
1.50
1.70
2.00

我的架构:

chapterno:
  type: float(4)
  fixed: false
  unsigned: true
  primary: false
  notnull: true
  autoincrement: false

函数调用之前和之后的xdebug跟踪:

0.4769   12560704                                 -> sfOutputEscaperIteratorDecorator->__construct() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\escaper\sfOutputEscaper.class.php:125
0.4770   12560704                                   -> sfOutputEscaper->__construct() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\escaper\sfOutputEscaperIteratorDecorator.class.php:49
0.4770   12560944                                   -> IteratorIterator->__construct() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\escaper\sfOutputEscaperIteratorDecorator.class.php:51
0.4771   12560944                                     -> Doctrine_Record->getIterator() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Record.php:0
0.4771   12561384                                       -> Doctrine_Record_Iterator->__construct() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Record.php:2166
0.4771   12561384                                         -> Doctrine_Record->getData() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Record\Iterator.php:53
0.4771   12561416                                         -> ArrayIterator->__construct() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Record\Iterator.php:53
0.4771   12562056                             -> sfOutputEscaperIteratorDecorator->key() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\escaper\sfOutputEscaperIteratorDecorator.class.php:0
0.4772   12562088                               -> IteratorIterator->key() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\escaper\sfOutputEscaperIteratorDecorator.class.php:81
0.4772   12560272                             -> sfOutputEscaperIteratorDecorator->getChapterno() G:\Duc\xampp\htdocs\msym\apps\frontend\modules\book\templates\indexSuccess.php:5
0.4772   12560424                               -> sfOutputEscaperObjectDecorator->__call() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\escaper\sfOutputEscaperObjectDecorator.class.php:0
0.4772   12560456                                 -> count() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\escaper\sfOutputEscaperObjectDecorator.class.php:47
0.4772   12560672                                 -> call_user_func_array() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\escaper\sfOutputEscaperObjectDecorator.class.php:64
0.4773   12561072                                   -> sfDoctrineRecord->__call() G:\Duc\xampp\htdocs\msym\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\record\sfDoctrineRecord.class.php:0
0.4773   12561200                                     -> substr()

我不需要这种功能,如何禁用此功能?

2 个答案:

答案 0 :(得分:2)

对我来说看起来像个错误。铸造浮动解决了它。就这样做:

echo (float) $chapter->getChapterNo();

您也可以覆盖getChapterNo()为您执行此操作(在您的覆盖中使用_get以避免使用__call()的无限循环。

<强>更新 我报告了此here,因此您可以根据需要订阅。

答案 1 :(得分:0)

也许你的架构中需要这种类型:

chapterno: { type: decimal, size: 2, scale: 1 }

要从数字中删除.0,您可以使用此PHP代码:

preg_match("/([0-9](\.[1-9]))|[0-9]/", $chapterno, $match);

当然$ match [0]是必需的结果。