Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Converters] Add toStringNoZero() function #4765

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ll2String(value);
} 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