Skip to content

Commit d60748e

Browse files
authored
Modified money tests to test the accuracies of floats (microsoft#944)
1 parent 27d5f64 commit d60748e

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

test/functional/pdo_sqlsrv/pdostatement_format_money_types.phpt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,9 @@ function testFloatTypes($conn, $numDigits)
6464

6565
trace("testFloatTypes: $floatVal1, $floatVal\n");
6666

67-
// Check if the numbers of decimal digits are the same
68-
// It is highly unlikely but not impossible
69-
$numbers = explode('.', $floatStr);
70-
$len = strlen($numbers[1]);
71-
if ($len == $numDigits && $floatVal1 != $floatVal) {
72-
echo "Expected $floatVal but $floatVal1 returned. \n";
73-
} else {
74-
$diff = abs($floatVal1 - $floatVal) / $floatVal;
75-
if ($diff > $epsilon) {
76-
echo "$diff: Expected $floatVal but $floatVal1 returned. \n";
77-
}
67+
$diff = abs($floatVal1 - $floatVal) / $floatVal;
68+
if ($diff > $epsilon) {
69+
echo "$diff: Expected $floatVal but $floatVal1 returned. \n";
7870
}
7971
}
8072
}

test/functional/sqlsrv/sqlsrv_statement_format_money_types.phpt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,10 @@ function testFloatTypes($conn)
6363
for ($i = 0; $i < count($values); $i++) {
6464
$floatStr = sqlsrv_get_field($stmt, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
6565
$floatVal = floatval($floatStr);
66-
67-
// Check if the numbers of decimal digits are the same
68-
// It is highly unlikely but not impossible
69-
$numbers = explode('.', $floatStr);
70-
$len = strlen($numbers[1]);
71-
if ($len == $numDigits && $floatVal != $floats[$i]) {
72-
echo "Expected $floats[$i] but returned ";
66+
$diff = abs($floatVal - $floats[$i]) / $floats[$i];
67+
if ($diff > $epsilon) {
68+
echo "$diff: Expected $floats[$i] but returned ";
7369
var_dump($floatVal);
74-
} else {
75-
$diff = abs($floatVal - $floats[$i]) / $floats[$i];
76-
if ($diff > $epsilon) {
77-
echo "$diff: Expected $floats[$i] but returned ";
78-
var_dump($floatVal);
79-
}
8070
}
8171
}
8272
} else {

0 commit comments

Comments
 (0)