function gmap_decimal in GMap Module 5
Same name and namespace in other branches
- 6.2 gmap.module \gmap_decimal()
- 6 gmap.module \gmap_decimal()
- 7.2 gmap.module \gmap_decimal()
- 7 gmap.module \gmap_decimal()
Utility function to allow high-precision decimals to work with the SQL layer. Use concatenation. (Apparently unquoted %s is bad.)
1 call to gmap_decimal()
File
- ./
gmap.module, line 1041 - GMap -- Routines to use the Google Maps API in Drupal.
Code
function gmap_decimal($num) {
// Paraphrased from postgresql documentation:
//
// Numbers in SQL can be in one of these forms:
// digits
// digits.[digits][e[+-]digits]
// [digits].digits[e[+-]digits]
// digitse[+-]digits
// where "digits" is one or more decimal digits.
// Trim extra whitespace
$num = trim($num);
// Check if we're in an acceptable form.
if (preg_match('/^[+\\-]?((\\d+)|(\\d+\\.\\d*)|(\\d*\\.\\d+))(e[+\\-]?\\d+)?$/', $num) === 1) {
// Good, we can pass that right along.
return $num;
}
// Otherwise, cast to float, possibly losing precision.
return (double) $num;
}