aboutsummaryrefslogtreecommitdiffstats
path: root/libdevcore
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-07-14 04:07:01 +0800
committerchriseth <chris@ethereum.org>2017-08-23 23:37:35 +0800
commit5bfd5d98c13b57c887eb09bffb9a03f2d1726b41 (patch)
treea1a6e908036b956b9dba33064f7212e9fde97b16 /libdevcore
parent1e05ebe50e0530beb62c96fc1112e935a5b11473 (diff)
downloaddexon-solidity-5bfd5d98c13b57c887eb09bffb9a03f2d1726b41.tar
dexon-solidity-5bfd5d98c13b57c887eb09bffb9a03f2d1726b41.tar.gz
dexon-solidity-5bfd5d98c13b57c887eb09bffb9a03f2d1726b41.tar.bz2
dexon-solidity-5bfd5d98c13b57c887eb09bffb9a03f2d1726b41.tar.lz
dexon-solidity-5bfd5d98c13b57c887eb09bffb9a03f2d1726b41.tar.xz
dexon-solidity-5bfd5d98c13b57c887eb09bffb9a03f2d1726b41.tar.zst
dexon-solidity-5bfd5d98c13b57c887eb09bffb9a03f2d1726b41.zip
Format numbers more nicely.
Diffstat (limited to 'libdevcore')
-rw-r--r--libdevcore/CommonData.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h
index 0321011e..5df8986a 100644
--- a/libdevcore/CommonData.h
+++ b/libdevcore/CommonData.h
@@ -145,6 +145,17 @@ inline std::string toHex(u256 val, HexPrefix prefix = HexPrefix::DontAdd)
return (prefix == HexPrefix::Add) ? "0x" + str : str;
}
+/// Returns decimal representation for small numbers and hex for large numbers.
+inline std::string formatNumber(bigint const& _value)
+{
+ if (_value < 0)
+ return "-" + formatNumber(-_value);
+ if (_value > 0x1000000)
+ return toHex(toCompactBigEndian(_value), 2, HexPrefix::Add);
+ else
+ return _value.str();
+}
+
inline std::string toCompactHexWithPrefix(u256 val)
{
std::ostringstream ret;