From 5bfd5d98c13b57c887eb09bffb9a03f2d1726b41 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 13 Jul 2017 22:07:01 +0200 Subject: Format numbers more nicely. --- libdevcore/CommonData.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'libdevcore/CommonData.h') 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; -- cgit