0
votes

I use cakephp 2.6.4. and sql srv 2012. I need to save decimal number in format decimal(4,2) -> 4 digits before , and 2 after separator.

In sql server i have data type decimal(4,2) and in model i have validation 'rule' => array('decimal',2).

When i try to save for example 4213,12 it reports message need to round number to 4213 or 4214 I tryed with dot (.) as delimiter, but not works

When i set data type in sql srv float, then i can save, but does not work with decimal,

Any help please? Tnx

  • next i tryed with numeric(4,2) in sql srv, but same thing as with decimal(4,2)

  • my validate array is: 'coordinate_x' => array( 'numeric' => array( 'rule' => array('decimal',2),

-and everything alse is commented

  • i managed to get SQL error: Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Error converting data type varchar to numeric. i removed validate rules for that field. it seems that dacimal value in cakephp equals character. but when i roll back validation rules, than i get error to round a number for example from 1234,12 to 1234 or 1235
2
What is the SQL INSERT/UPDATE that is being generated by Cake? - drmonkeyninja
i dont get any sql. by pressing submit i get red border around input field with massage. no sql is executed i think. and i think these massage is browsers massage and is connected with database data type. is it possible? - marko_b123
It sounds like the data is failing on validation and therefore CakePHP is not attempting to update the database. Could you update your question with your model's $validate array? - drmonkeyninja

2 Answers

2
votes

Resolwed with HTML requirement:

<input type="number" step="0.01">
1
votes

$this->Number->format(); can be used to change the format of the number.

Example:

$this->Number->format(floor($session->read('max_price')), 
      array('escape' => false, 
            'places' => 0, 
             'thousands' => ','
      ));

Place attribute is used to set the decimal value .