From 5157d7a7477065b788904ac5241e4f4aa1671f2f Mon Sep 17 00:00:00 2001 From: Ellen Papsch Date: Tue, 28 Jan 2020 11:29:11 +0100 Subject: [PATCH] fromFloat: Ensure dot as decimal point. String conversion is locale aware, because its primary use case is for display purposes. This hack assumes that the only other decimal point is a comma, which gets replaced by dot. Alternatively, locale could be set to C before conversion and restored after conversion, although this might incur an performance penalty, because setlocale does I/O. --- src/Decimal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Decimal.php b/src/Decimal.php index 2a374ae..e48380f 100644 --- a/src/Decimal.php +++ b/src/Decimal.php @@ -90,7 +90,7 @@ public static function fromFloat(float $fltValue, int $scale = null): Decimal throw new NaNInputError("fltValue can't be NaN"); } - $strValue = (string) $fltValue; + $strValue = str_replace(',', '.', (string) $fltValue); $hasPoint = (false !== \strpos($strValue, '.')); if (\preg_match(self::EXP_NUM_GROUPS_NUMBER_REGEXP, $strValue, $capture)) {