-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
171 additions
and
154 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Calculator | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2021 Pronamic | ||
* @copyright 2005-2022 Pronamic | ||
* @license GPL-3.0-or-later | ||
* @package Pronamic\WordPress\Number | ||
*/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* BC Math Calculator | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2021 Pronamic | ||
* @copyright 2005-2022 Pronamic | ||
* @license GPL-3.0-or-later | ||
* @package Pronamic\WordPress\Number | ||
*/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* PHP Calculator | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2021 Pronamic | ||
* @copyright 2005-2022 Pronamic | ||
* @license GPL-3.0-or-later | ||
* @package Pronamic\WordPress\Number | ||
*/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Number | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2021 Pronamic | ||
* @copyright 2005-2022 Pronamic | ||
* @license GPL-3.0-or-later | ||
* @package Pronamic\WordPress\Number | ||
*/ | ||
|
@@ -377,45 +377,38 @@ private static function parse_float( $value ) { | |
* @link https://stackoverflow.com/questions/48205572/json-encode-float-precision-in-php7-and-addition-operation | ||
* @link https://bugs.php.net/bug.php?id=75800 | ||
*/ | ||
|
||
/** | ||
* It seems that precision setting was different before PHP 7.1, | ||
* so we're trying to force this precision. | ||
*/ | ||
if ( \version_compare( \PHP_VERSION, '7.1', '<' ) ) { | ||
return self::parse_float_with_precision( $value, '14' ); // @codeCoverageIgnore | ||
|
||
} | ||
|
||
return self::parse_mixed( \wp_json_encode( $value ) ); | ||
return self::parse_float_with_precision( $value, -1 ); | ||
} | ||
|
||
/** | ||
* Parse float precission. | ||
* | ||
* @codeCoverageIgnore | ||
* @param float $value Value. | ||
* @param string $precision Precision. | ||
* @param float $value Value. | ||
* @param int $precision Precision. | ||
* @psalm-return numeric-string | ||
* @return string | ||
*/ | ||
private static function parse_float_with_precision( $value, $precision ) { | ||
// phpcs:ignore WordPress.PHP.IniSet.Risky | ||
$ini_precision = \ini_set( 'precision', $precision ); | ||
public static function parse_float_with_precision( $value, $precision ) { | ||
$option = 'serialize_precision'; | ||
|
||
/** | ||
* The `serialize_precision` option was introduced in PHP 7.1. | ||
* | ||
* @link https://wiki.php.net/rfc/precise_float_value | ||
*/ | ||
if ( \version_compare( \PHP_VERSION, '7.1', '<' ) ) { | ||
$option = 'precision'; | ||
} | ||
|
||
// phpcs:ignore WordPress.PHP.IniSet.Risky | ||
$ini_serialize_precision = \ini_set( 'serialize_precision', $precision ); | ||
$ini_serialize_precision = \ini_set( $option, (string) $precision ); | ||
|
||
$result = self::parse_mixed( \wp_json_encode( $value ) ); | ||
|
||
if ( false !== $ini_precision ) { | ||
// phpcs:ignore WordPress.PHP.IniSet.Risky | ||
\ini_set( 'precision', $ini_precision ); | ||
} | ||
|
||
if ( false !== $ini_serialize_precision ) { | ||
// phpcs:ignore WordPress.PHP.IniSet.Risky | ||
\ini_set( 'serialize_precision', $ini_serialize_precision ); | ||
\ini_set( $option, $ini_serialize_precision ); | ||
} | ||
|
||
return $result; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Parser | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2021 Pronamic | ||
* @copyright 2005-2022 Pronamic | ||
* @license GPL-3.0-or-later | ||
* @package Pronamic\WordPress\Number | ||
*/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Bootstrap tests | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2021 Pronamic | ||
* @copyright 2005-2022 Pronamic | ||
* @license GPL-3.0-or-later | ||
* @package Pronamic\WordPress\Money | ||
*/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* BC Math Calculator Test | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2021 Pronamic | ||
* @copyright 2005-2022 Pronamic | ||
* @license GPL-3.0-or-later | ||
* @package Pronamic\WordPress\Money | ||
*/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* PHP Calculator Test | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2021 Pronamic | ||
* @copyright 2005-2022 Pronamic | ||
* @license GPL-3.0-or-later | ||
* @package Pronamic\WordPress\Money | ||
*/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* PHP Calculator Test | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2021 Pronamic | ||
* @copyright 2005-2022 Pronamic | ||
* @license GPL-3.0-or-later | ||
* @package Pronamic\WordPress\Money | ||
*/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Number Test | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2021 Pronamic | ||
* @copyright 2005-2022 Pronamic | ||
* @license GPL-3.0-or-later | ||
* @package Pronamic\WordPress\Money | ||
*/ | ||
|
@@ -529,4 +529,18 @@ public function test_number_from_number() { | |
|
||
$this->assertSame( '5', $number->get_value() ); | ||
} | ||
|
||
/** | ||
* Test HelpScout ticket #23013. | ||
* | ||
* @link https://github.com/pronamic/wp-pronamic-pay/issues/281 | ||
* @group ticket23013 | ||
*/ | ||
public function test_helpscout_ticket_23013() { | ||
$value = 29.95; | ||
|
||
$result = Number::parse_float_with_precision( $value, 17 ); | ||
|
||
$this->assertSame( '29.949999999999999', $result ); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Parser | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2021 Pronamic | ||
* @copyright 2005-2022 Pronamic | ||
* @license GPL-3.0-or-later | ||
* @package Pronamic\WordPress\Number | ||
*/ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.