- Changed integer to decimal conversion from php::toDecimal(php::toString(expr)) to direct php::toDecimal(expr) - Added test case to verify decimal integer operand does not convert through string - Created new test file decimal-int-operand.php to test decimal multiplication with integer operands - Added phpt test for decimal multiplication accepting Int and dynamically typed Int operands - Fixed type conversion trait to handle INT type directly without string conversionpull/44/head
parent
21d0224769
commit
e345b0d82a
4 changed files with 70 additions and 1 deletions
@ -0,0 +1,22 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
function multiplyDecimalByInt(int $factor): string |
||||||
|
{ |
||||||
|
$value = std::decimal('123.456'); |
||||||
|
$value = $value * 1000; |
||||||
|
$value = $value * $factor; |
||||||
|
return $value->toString(); |
||||||
|
} |
||||||
|
|
||||||
|
function multiplyDecimalByVar($factor): string |
||||||
|
{ |
||||||
|
$value = std::decimal('123.456'); |
||||||
|
$value = $value * $factor; |
||||||
|
return $value->toString(); |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
echo multiplyDecimalByInt(1000), "\n"; |
||||||
|
echo multiplyDecimalByVar(1000), "\n"; |
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
--TEST-- |
||||||
|
Decimal multiplication accepts Int and dynamically typed Int operands |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
function multiplyDecimal($factor): string |
||||||
|
{ |
||||||
|
$value = std::decimal('123.456'); |
||||||
|
$value = $value * $factor; |
||||||
|
return $value->toString(); |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$value = std::decimal('123.456'); |
||||||
|
echo ($value * 1000)->toString(), "\n"; |
||||||
|
echo multiplyDecimal(1000), "\n"; |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
123456.000 |
||||||
|
123456.000 |
||||||
Loading…
Reference in new issue