Skip to content

Commit

Permalink
Merge pull request #3 from krissss/2-科学计数法问题
Browse files Browse the repository at this point in the history
feat: 使用 number_format 解决科学计数法问题
  • Loading branch information
krissss authored Jun 5, 2024
2 parents dbe843c + c030ed7 commit 4fd148d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/BCS.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function __call($name, $arguments)
throw new \Exception("{$bcName} not in ::bcEnables");
}
foreach ($arguments as $number) {
$number = number_format($number, $this->config['operateScale']+1, '.', '');
if ($bcName === 'bcpow') {
$number = intval($number);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/IssueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use kriss\bcmath\BCS;
use PHPUnit\Framework\TestCase;

class IssueTest extends TestCase
{
// https://github.com/krissss/bcmath/issues/2
public function testIssues2()
{
$total = BCS::create(0, ['scale' => 6]);
$total->add(1);
$total->add(0.000008);

$this->assertEquals(1.000008, $total->getResult());
}
}

0 comments on commit 4fd148d

Please sign in to comment.