smarty 将字符串转换为 Integer/Float
smarty convert string to Integer/Float
我有一些字符串值,比如 $value = "123.45";
。
因为我要比较这个$value
和Integer,所以我需要把$value
的类型转换成float。
如何将 String 转换为 smarty 语言中的 Integer/Float?
谢谢。
你可以在smarty中使用php的函数floatval / intval:
{$value = $value|floatval}
{$value = $value|intval}
乘以 1 也可以:
{$value = $value*1}
我有一些字符串值,比如 $value = "123.45";
。
因为我要比较这个$value
和Integer,所以我需要把$value
的类型转换成float。
如何将 String 转换为 smarty 语言中的 Integer/Float?
谢谢。
你可以在smarty中使用php的函数floatval / intval:
{$value = $value|floatval}
{$value = $value|intval}
乘以 1 也可以:
{$value = $value*1}