Skip to content

Commit

Permalink
Converter float precision (#445)
Browse files Browse the repository at this point in the history
* handle large conversion ratios

* increase precision

* fix docblock
  • Loading branch information
bendavies authored and frederikbosch committed Jan 19, 2018
1 parent dd80a67 commit fbf11e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ public static function fromString($number)
/**
* @param float $floatingPoint
*
* @return Number
* @return self
*/
public static function fromFloat($floatingPoint)
{
if (is_float($floatingPoint) === false) {
throw new \InvalidArgumentException('Floating point expected');
}

return self::fromString(sprintf('%.8F', $floatingPoint));
return self::fromString(sprintf('%.14F', $floatingPoint));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public function convertExamples()
['XBT', 'USD', 8, 2, 6597, 10, 0],
['XBT', 'USD', 8, 2, 6597, 100, 1],
['ETH', 'EUR', 18, 2, 330.84, '100000000000000000', 3308],
['BTC', 'USD', 8, 2, 13500, 100000000, 1350000],
['USD', 'BTC', 2, 8, 1 / 13500, 1350000, 100000000],
];
}
}

0 comments on commit fbf11e9

Please sign in to comment.