From a422d877b07168866973cc8aec1da469916d4237 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Thu, 11 Jan 2018 15:59:41 +0800 Subject: [PATCH] Quantity formatter. --- src/Formatters/QuantityFormatter.php | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/Formatters/QuantityFormatter.php diff --git a/src/Formatters/QuantityFormatter.php b/src/Formatters/QuantityFormatter.php new file mode 100644 index 0000000..f4c9153 --- /dev/null +++ b/src/Formatters/QuantityFormatter.php @@ -0,0 +1,33 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Formatters; + +use InvalidArgumentException; +use Web3\Utils; +use Web3\Formatters\IFormatter; + +class QuantityFormatter implements IFormatter +{ + /** + * format + * + * @param mixed $value + * @return string + */ + public static function format($value) + { + $value = Utils::toString($value); + $bn = Utils::toBn($value); + + return '0x' . $bn->toHex(true); + } +} \ No newline at end of file