Reputation: 10094
Ive got data coming in from an xml feed the attribute that im using from this feed is written Decimal="1.14"
and Decimal="2.00"
what i want to do is use these attributes in a function and to be able to compare them.
like this
if($provider1 > $provider2){
return $provider1;
}
else {
return $provider2;
}
How can i convert these numbers into a float to be used in the function
Upvotes: 0
Views: 61
Reputation: 7362
Try this function: floatval
The documentation is here: http://php.net/manual/en/function.floatval.php
You can then do something like this:
if (floatval($provider1) > floatval($provider2)) {
return $provider1;
} else {
return $provider2;
}
Upvotes: 3
Reputation: 11586
You can use floatval($value)
or (float) $value
. See type-casting here: http://php.net/manual/en/language.types.type-juggling.php
Upvotes: 1
Reputation: 874
You can use floatval() to convert string to float. To get the strings use any xml library.
Upvotes: 0