gpt4 book ai didi

php - Yii2:如何格式化 ActiveField 中的值?

转载 作者:行者123 更新时间:2023-12-02 00:43:20 25 4
gpt4 key购买 nike

在我的表格上我有这个:

echo $form->field($model, 'amount')->textInput();

如果来自数据库的值是 42.5,我想在输入字段中将其格式化为两位小数,例如 42.50。我该怎么做?

我在 ActiveField 中找不到任何关于格式化的信息文档...

最佳答案

您可以使用格式化程序功能

$form->field($model, 'amount', 
['inputOptions' => ['value' => Yii::$app->formatter->asDecimal($model->amount)]])

http://www.yiiframework.com/doc-2.0/yii-i18n-formatter.html

http://www.yiiframework.com/doc-2.0/guide-output-formatting.html

关于php - Yii2:如何格式化 ActiveField 中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45359775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com