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
thanks
This question is related to
php
For arbitrary precision mathematics PHP offers the Binary Calculator which supports numbers of any size and precision, represented as strings.
$s = '1234.13';
$double = bcadd($s,'0',2);
Use doubleval()
. But be very careful about using decimals in financial transactions, and validate that user input very carefully.
Why is floatval the best option for financial comparison data? bc functions only accurately turn strings into real numbers.
Source: Stackoverflow.com