如何在Laravel中格式化为包含逗号和点的十进制数字? [英] How to format to decimal number that include comma and dot in laravel?
问题描述
我想知道如何格式化我的数字,包括逗号和点到小数.谢谢.在我的数据库中,我的金额栏是(16,8)的十进制类型.格式化后,我想将我的电话号码保存到数据库中.例如 我的输入号码10,000.1111,并想另存为10000.1111到我的数据库中.谢谢.
I would like to know that how can i format my number including comma and dot to decimal. Thanks. In my database , my amount column is decimal type with (16,8) . after i formatting i want to save to database my number . For example my input number 10,000.1111 and want to save as a 10000.1111 to my database. Thanks.
推荐答案
您可以使用它来将字符串格式化为浮点格式,并删除逗号.
You could use this to format the string to a float, and remove the commas.
(float) str_replace(',', '', '10,000.1111')
类型转换(float)
将强制输出变量为浮点型.然后str_replace()
将从输入的变量中删除逗号.
Typecasting (float)
will force the outputted variable as a float. And str_replace()
will remove the commas from the inputted variable.
$input = '10,000.1111';
$model->column = (float) str_replace(',', '', $input);
$model->save()
这篇关于如何在Laravel中格式化为包含逗号和点的十进制数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!