Skip to content

Commit

Permalink
[Converters] Add toStringNoZero() function
Browse files Browse the repository at this point in the history
  • Loading branch information
tonhuisman committed Aug 15, 2023
1 parent c25341d commit dfcf29f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/src/Helpers/StringConverter_Numerical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ String trimTrailingZeros(const String& value) {

}

/**
* Helper: Convert an integer to string, but return an empty string for 0, to save a little space in settings
*/
String toStringNoZero(int64_t value) {
if (value != 0) {
return toString(value, 0);
} else {
return EMPTY_STRING;
}
}

#if FEATURE_USE_DOUBLE_AS_ESPEASY_RULES_FLOAT_TYPE
String doubleToString(const double& value, unsigned int decimalPlaces, bool trimTrailingZeros_b) {
// This has been fixed in ESP32 code, not (yet) in ESP8266 code
Expand Down
2 changes: 2 additions & 0 deletions src/src/Helpers/StringConverter_Numerical.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ String ll2String(int64_t value,

String trimTrailingZeros(const String& value);

String toStringNoZero(int64_t value);

#if FEATURE_USE_DOUBLE_AS_ESPEASY_RULES_FLOAT_TYPE
String doubleToString(const double& value,
unsigned int decimalPlaces = 2,
Expand Down

0 comments on commit dfcf29f

Please sign in to comment.