繁体   English   中英

通过javascript在文本字段中输入货币格式

[英]currency format in text field through javascript

我想使文本字段的货币格式为小数点后两位。 问题是:-货币格式后,我的值的第一位保存在db中,而不是完整值。

这是代码:-

html:-
<?php $itemcost=$item->price;?>
                        <label for="item-price" class="required item-dollar">$</label>
                        <input type="text" class="form-control" required="required" 
                                       value="{{number_format($itemcost)}}" id="item-pricing" 
                                       name="price" placeholder="Item Price">

请告诉我任何解决方案。

目前尚不清楚您是否难以将货币保存到数据库或显示数据库

您需要将值存储在接受小数/浮点数的字段中(例如,decimal(10,2)

您还使用了number_format()而没有第二个参数,该参数默认不带小数位,您应该使用number_format($ itemcost,2)保留两个小数位

<?php $itemcost=$item->price;?>
<label for="item-price" class="required item-dollar">$</label>
<input type="text" class="form-control" required="required" value="{{number_format($itemcost,2)}}" id="item-pricing" name="price" placeholder="Item Price">

http://php.net/number_format

暂无
暂无

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

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