我有一個數(shù)字,它已經(jīng)轉(zhuǎn)換為一千個分隔符,但在模型中使用 number_format() 助手進行全局設(shè)置。因此,當已轉(zhuǎn)換的數(shù)字收到 number_format 幫助程序時,我收到錯誤消息:(1/1) ErrorException
A non well formed numeric value encountered我試圖在 number_format() 助手之前檢查模型函數(shù),數(shù)字是否已經(jīng)是千位格式。我不想修改現(xiàn)有代碼,我只能在用 number_format() 轉(zhuǎn)換之前修改模型函數(shù)。任何可用的功能/助手?
1 回答

慕運維8079593
TA貢獻1876條經(jīng)驗 獲得超5個贊
您可以檢查$value是否是int然后應用格式,如果不是則表示它已經(jīng)格式化,請使用:
if(is_int($value))
{
$value = number_format($value, 2); // as an example here.
}
正如@Jerodev 在評論中提到的那樣,您可能使用的是浮點數(shù),因此.將被視為數(shù)字的一部分,但,不會,因此如果您使用,可以is_numeric用來檢查的數(shù)字格式化數(shù)字,它將返回 false如果數(shù)字已經(jīng)格式化并包含,.
- 1 回答
- 0 關(guān)注
- 144 瀏覽
添加回答
舉報
0/150
提交
取消