Skip to content

Instantly share code, notes, and snippets.

@mahdiyazdani
Created November 1, 2020 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahdiyazdani/c6a8878eb79ab64a3f944e1d3a36b1a6 to your computer and use it in GitHub Desktop.
Save mahdiyazdani/c6a8878eb79ab64a3f944e1d3a36b1a6 to your computer and use it in GitHub Desktop.
Convert a float to a string without locale formatting
<?php
/**
* Convert a float to a string without locale formatting which PHP adds when changing floats to strings.
*
* @param float $float Float value to format.
* @return string
*/
function prefix_float_to_string( $float ) {
if ( ! is_float( $float ) ) {
return $float;
}
$locale = localeconv();
$string = strval( $float );
$string = str_replace( $locale['decimal_point'], '.', $string );
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment