【发布时间】:2016-11-26 13:01:23
【问题描述】:
我想在 Codeigniter 中创建自己的数字格式化助手。但是当我调用我的函数时,它会显示一个错误:
严重性:通知
消息:遇到格式不正确的数值
这是我的辅助函数:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('test_method'))
{
function test_method($var = '')
{
return number_format( (float) $var, 0, ',', '.');
}
}
当我在视图中执行时:
<?php echo test_method($price) ?>
我收到了上述通知。如何解决?
【问题讨论】:
-
$price里面有什么? -
数据库中的值
-
喜欢
-
使用我答案中的代码(更新为抛出异常),看看值是什么。果然不适合数字格式。您可能需要在格式化之前对其进行准备,或者确保仅将正确的值保存为价格。
标签: php codeigniter