Skip to content

Commit

Permalink
better output formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Dec 19, 2023
1 parent f720f8f commit f25f544
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/source/doxygen-docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- mrpt::maps::CSimpleMap changes:
- Added an optional twist field.
- Simplified API for preferred usage with structured binding tuples.
- \ref mrpt_system_grp
- More readable results in mrpt::system::unitsFormat() for the special case of exactly `0`.
- BUG FIXES:
- Fix filtering of NANs input point clouds in mrpt::maps::CPointsMap::insertAnotherMap().

Expand Down
10 changes: 9 additions & 1 deletion libs/system/include/mrpt/system/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,15 @@ bool decodeBase64(const std::string& inString, std::vector<uint8_t>& outData);

/** This function implements formatting with the appropriate SI metric unit
* prefix: 1e-12->'p', 1e-9->'n', 1e-6->'u', 1e-3->'m', 1->'', 1e3->'K',
* 1e6->'M', 1e9->'G', 1e12->'T' \sa intervalFormat */
* 1e6->'M', 1e9->'G', 1e12->'T'
* If the input is exactly 0, it will return the string `"0"`, so the overall
* result looks like that (e.g. using meter units on the caller side):
* \code
* 13445.0 => 13.44 km
* 0.0 => 0 m
* \endcode
* \sa
* intervalFormat */
std::string unitsFormat(
const double val, int nDecimalDigits = 2, bool middle_space = true);

Expand Down
3 changes: 3 additions & 0 deletions libs/system/src/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ std::string mrpt::system::unitsFormat(
double mult;
const double aVal = std::abs(val);

// special case for 0:
if (val == 0) return middle_space ? "0 " : "0";

if (aVal >= 1e12)
{
mult = 1e-12;
Expand Down

0 comments on commit f25f544

Please sign in to comment.