Created
November 1, 2020 22:48
-
-
Save mahdiyazdani/c6a8878eb79ab64a3f944e1d3a36b1a6 to your computer and use it in GitHub Desktop.
Convert a float to a string without locale formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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