function gmap_decimal in GMap Module 7.2
Same name and namespace in other branches
- 5 gmap.module \gmap_decimal()
- 6.2 gmap.module \gmap_decimal()
- 6 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.) @todo move this to GmapPolylineToolbox or GmapToolbox
File
- ./
gmap.module, line 1181 - 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;
}