0

I have in my database the ff. float:

1 1.5 1.7 2 

I need to keep this as is in the program, but somehow symfony automatically convert these to ff by default:

1.00 1.50 1.70 2.00 

My schema:

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

xdebug trace before and after the function call:

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() 

I don't need this kind of functionality, how can i disable this?

10
  • $c->getChapterno();-> this is my code Commented Jul 11, 2011 at 13:29
  • What does your database schema look like? Do you use a FLOAT column? Or DECIMAL perhaps? Commented Jul 11, 2011 at 13:59
  • I've added the Schema on my post. :) Commented Jul 11, 2011 at 14:05
  • What is the type of the data you are displaying (use var_dump()) to determine whether it is string or float)? Commented Jul 11, 2011 at 21:01
  • it's string. how can i prevent symfony auto convert to string? Commented Jul 12, 2011 at 2:40

2 Answers 2

2

Looks like a bug to me. Casting to float solves it. Just do this:

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

You may also override getChapterNo() to do this for you (use _get in your override to avoid infinite loops with __call().

UPDATE I reported this here, so you can subscribe if you want.

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe you need this type in your schema:

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

To remove .0 from the number you can use this php code:

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

Of course $match[0] is the needed result.

4 Comments

the output of this will be 1.0 and 1.5.
In my form I get this result.
is there anyway to just return the plain result without padding .0? i currently using trim to remove unnecessary part, but it's not program wide.
I mean regex can do this work. The pattern ([0-9](\.[1-9]))|[0-9] removes .0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.