文本输入自动小数

时间:2017-01-17 02:39:28

标签: php yii textinput

如何使用十进制','?

自动输入文本
<td><?= $form->field($model, 'Payment')->textInput(['maxlength' => 7, 'style' => 'width:120px;'])?></td>

enter image description here

4 个答案:

答案 0 :(得分:1)

<td><?= $form->field($model, 'Payment')->textInput([
    'maxlength' => 7,
    'style' => 'width:120px;'
    'type' => 'number', // this will set input to decimal number format
    'step' => '0.0001' // and this
])?></td>

答案 1 :(得分:0)

<input type="number" id="decimalvalue" name="decimalvalue" onkeyup="setDecimalValue()">

<script>
    function setDecimalValue() {
        var num = $('#decimalvalue').val();
        var n = num.toFixed(2);
        $('#decimalvalue').val(n);
    }
</script>

答案 2 :(得分:0)

在yii中,我们有自定义数字格式选项。为此,我们必须覆盖现有的格式函数。

您可以参考以下链接了解更多详情。 http://www.yiiframework.com/wiki/360/custom-number-formatting-or-decimal-separators-and-i18n/

答案 3 :(得分:0)

<input type="number" onchange="setTwoNumberDecimal" min="0" max="10" step="0.25" value="0.00" />

function setTwoNumberDecimal(event) {
    this.value = parseFloat(this.value).toFixed(2);
}