0

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
4
  • What is the SQL INSERT/UPDATE that is being generated by Cake? Commented Jun 2, 2015 at 8:56
  • 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? Commented Jun 2, 2015 at 9:04
  • 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? Commented Jun 2, 2015 at 9:36
  • See github.com/dereuromark/cakephp-tools/blob/2.x/Model/Behavior/… Commented Jun 2, 2015 at 9:37

2 Answers 2

3

Resolwed with HTML requirement:

<input type="number" step="0.01">
Sign up to request clarification or add additional context in comments.

Comments

1

$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 .

6 Comments

that can i set in controllers beforeSave, i guess?
No is not work in controller,Its works only view file
but in view i have only a row for that field: echo $this->Form->input('coordinate_x', array('label' => 'Koordinata X', 'title' => 'x u htrs'));
Can use with help of Java script to change the format number while u have typing in text box wait i post the link
digitalbush.com/projects/masked-input-plugin use link to change format of number while u have typing in the input box
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.