简体   繁体   English

Yii框架-使用十进制属性保存模型

[英]Yii framework - save model with decimal property

I have column in the database with type of column decimal(10,2). 我在数据库中的列类型为十进制(10,2)。

When I try it save model with number (for example 45.28), so the value stored in the database is 45.00 当我尝试使用数字保存模型时(例如45.28),因此存储在数据库中的值为45.00

Why are not saved number after the decimal point? 为什么小数点后不保存数字?

Where is the problem? 问题出在哪儿?

Thanks 谢谢

If you created the model using Gii, make sure that in rules() the property integerOnly is false . 如果使用Gii创建模型,请确保在rules() ,属性integerOnlyfalse

array(......'numerical', 'integerOnly'=>false);

Another possible solutions: 另一个可能的解决方案:

array('your-attribute', 'type', 'type'=>'float'),
array('your-attribute', 'match', 'pattern'=>'/^[0-9]{1,10}(\.[0-9]{0,2})?$/'),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM