Forget all the rtrims, and regular expressions, coordinates are floats and should be treated as floats, just prepend the variable with (float) to cast it from a string to a float:

$string = "37.422005000000000000000000000000";
echo (float)$string;

output:

37.422005

The actual result you have are floats but passed to you as strings due to the HTTP Protocol, it's good to turn them back into thier natural form to do calculations etc on.

Test case: http://codepad.org/TVb2Xyy3

Note: Regarding the comment about floating point precision in PHP, see this: https://stackoverflow.com/a/3726761/353790

Answer from RobertPitt on Stack Overflow
🌐
Tek-Tips
tek-tips.com › home › forums › software › programmers › web development › php
Remove trailing zeroes | Tek-Tips
August 26, 2004 - I use number_format to get the 3 decimal places. 8.124669 is fine as "8.125" What I don't want is "8.500" but "8.5" If I get "8.125" I need "8.125" not "8.1" If I get "6.250" I need "6.25" not "6.250" or "6.3" If I get "11.000" I want "11" not "11.000" Is there a way I can test the stress the difference of the loop vs a regex? ... <?php print '<pre>'; $a = array (8.500, 8.125, 6.250, 11.000); foreach ($a as $b) { print rtrim ($b, '.0'); print "\n"; } ?> Outputs:
Discussions

numbers - Remove useless zero digits from decimals in PHP - Stack Overflow
Why '-12.345,000000,000' will be '-12.345,000000' not '-12.345'? Because this function is for remove zero digits (include zero trails) from decimal value. It is not validation for the correct number format. More on stackoverflow.com
🌐 stackoverflow.com
How would I omit zero value decimals in a number format? - Craft CMS Stack Exchange
This limits it to 4 places and trims only trailing zeroes. More on craftcms.stackexchange.com
🌐 craftcms.stackexchange.com
June 27, 2014
magento 1.9 - Remove trailing zeros - Magento Stack Exchange
Im setting up Google trusted stores and I need to call some information which I can do but the format is wrong. From what I can see there is 2 extra zero's at the and of the numbers which I need to More on magento.stackexchange.com
🌐 magento.stackexchange.com
September 21, 2015
Remove trailing zeroes
Is there a function that I can't find that will remove trailing zeroes from a number with a decimal? I can't find one so I'm creating one now ... Thanks ericbrunson for pointing me but this is exactly what I wanted. ... The PHP manual recommends not using regular expression functions where ... More on tek-tips.com
🌐 tek-tips.com
13
0
July 12, 2025
🌐
Web-profile
web-profile.net › php › dev › php-remove-trailing-zeros
php remove trailing zeros of a decimal number – web-profile
Method to remove or strip trailing zeros of a decimal number: function clean_num( $num ){ $pos = strpos($num, '.'); if($pos === false) { // it is integer number return $num; }else{ // it is decimal number return rtrim(rtrim($num, '0'), '.'); } } Works on numbers: 0.02=0.02; 4.000=4; 80=80.
🌐
Kelly
justin.kelly.org.au › php-remove-trailing-and-leading-zeros
PHP remove trailing and leading zeros · Justin Kelly
May 12, 2010 - <?php /* * Function: number_clean * Purpose: Remove trailing and leading zeros - just to return cleaner number */ public function number_clean($num){ //remove zeros from end of number ie. 140.00000 becomes 140. $clean = rtrim($num, '0'); //remove zeros from front of number ie.
🌐
PHP
php.net › manual › en › function.number-format.php
PHP: number_format - Manual
I also wrote this : function ... $locale['thousands_sep']); } hope this helps =) []'s ... For Zero fill - just use the sprintf() function $pr_id = 1; $pr_id = sprintf("d", $pr_id); echo $pr_id; //outputs 001 ----------------- ...
Find elsewhere
🌐
CopyProgramming
copyprogramming.com › howto › php-remove-0-after-decimal-from-number-php
Php: Eliminating trailing zeros after decimal in PHP numbers
April 11, 2023 - Before proceeding, it is essential to ensure that your data is first converted to a string format. How to strip trailing zeros in PHP, // remove leading zeros $output = ltrim ($output, "0"); // remove trailing 0s. $temp=explode(".",$output); $temp[1]= ... function removeFirstZeroToEnd($number) ...
🌐
Homedutech
homedutech.com › program-example › numbers--remove-useless-zero-digits-from-decimals-in-php.html
Remove useless zero digits from decimals in PHP
To remove unnecessary zero digits from decimals in PHP, you can use the number_format function in combination with rtrim. Here's an example: $number = 123.4500; // Convert the number to a string with a maximum of 10 decimal places $formattedNumber = rtrim(number_format($number, 10), '0'); // ...
🌐
Tek-Tips
tek-tips.com › home › forums › software › programmers › web development › php
Remove trailing zeroes - PHP
July 12, 2025 - I use number_format to get the 3 decimal places. 8.124669 is fine as "8.125" What I don't want is "8.500" but "8.5" If I get "8.125" I need "8.125" not "8.1" If I get "6.250" I need "6.25" not "6.250" or "6.3" If I get "11.000" I want "11" not "11.000" Is there a way I can test the stress the difference of the loop vs a regex? ... <?php print '<pre>'; $a = array (8.500, 8.125, 6.250, 11.000); foreach ($a as $b) { print rtrim ($b, '.0'); print "\n"; } ?> Outputs:
🌐
TheoryApp
theoryapp.com › format-numbers-with-leading-and-trailing-zeros-in-php
Format numbers with leading and trailing zeros in PHP – TheoryApp
December 11, 2014 - PHP › Format numbers with leading and trailing zeros in PHP · theoryapp Posted on December 11, 2021 Posted in PHP · PHP provides str_pad() to add a string to a certain length with another string. Another way is to use sprintf() with formatting patterns. Pad leading zeros to get exactly 3 digits: $value = 12; sprintf('d', $value); // 012 str_pad($value, 3, '0', STR_PAD_LEFT); // 012 · comments · Customize Mediawiki To Remove Management Links ·
🌐
CodeGenes
codegenes.net › blog › remove-useless-zero-digits-from-decimals-in-php
How to Remove Useless Zero Digits from Decimals in PHP: Fast & Optimized Methods — codegenes.net
Floating-Point Risks: Fails for ... number of decimal places you need (e.g., 2 for currency), number_format() is a built-in function that rounds and formats numbers....