将字符串转换为双精度字符串-这可能吗? [英] Convert a string to a double - is this possible?
本文介绍了将字符串转换为双精度字符串-这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是想知道在php中,是否可以将字符串转换为双精度型.我正在使用提供价格作为字符串的金融网络服务.我真的需要将其处理为一个双,并想知道如何将其转换
Just wondering in php, if it was possible to convert a string to a double. I am using a financial web service which provides a price as a string. I really need to process this as a double and was wondering how i would convert it
谢谢
推荐答案
只需使用 floatval()
.
例如:
$var = '122.34343';
$float_value_of_var = floatval($var);
echo $float_value_of_var; // 122.34343
如果您想知道 doubleval()
只是一个别名表示floatval()
.
另一个说法是,在金融应用中,浮点值至关重要,因为浮点值不够精确.例如.添加两个浮点数可能会导致类似12.30000000001
的情况,并且此错误可能会传播.
And as the other say, in a financial application, float values are critical as these are not precise enough. E.g. adding two floats could result in something like 12.30000000001
and this error could propagate.
这篇关于将字符串转换为双精度字符串-这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文