Search code examples
sql-servercakephpdecimalcakephp-2.6

Cakephp sql decimal input form


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

Solution

  • Resolwed with HTML requirement:

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