MCPcopy Create free account
hub / github.com/chen3feng/toft / FormatMeasure

Function FormatMeasure

base/string/number.cpp:906–921  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

904} // namespace
905
906std::string FormatMeasure(double n, const char* unit)
907{
908 // see http://zh.wikipedia.org/wiki/%E5%9B%BD%E9%99%85%E5%8D%95%E4%BD%8D%E5%88%B6%E8%AF%8D%E5%A4%B4
909 static const char* const base_prefixes[] = {
910 "y", "z", "a", "f", "p", "n", "u", "m", // negative exponential
911 "", "k", "M", "G", "T", "P", "E", "Z", "Y"
912 };
913 static const int negative_prefixes_size = 8;
914 static const int prefixes_size = TOFT_ARRAY_SIZE(base_prefixes);
915
916 const char* const* prefixes = base_prefixes + negative_prefixes_size;
917
918 return NumberToHumanReadableString<double, 1000>(
919 n, prefixes, unit, -negative_prefixes_size,
920 prefixes_size - negative_prefixes_size - 1);
921}
922
923std::string FormatBinaryMeasure(int64_t n, const char* unit)
924{

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68