diff options
author | login <login@tilde.team> | 2023-11-25 19:38:14 +0000 |
---|---|---|
committer | login <login@tilde.team> | 2023-11-25 19:38:14 +0000 |
commit | 1885cebc20732994279d23300ed4f437db7d584f (patch) | |
tree | 2c8b9e88e4d9da022d9a37aa3892bee278c2484b | |
parent | 478534343c42e53460de85b596b55bdecd4115e4 (diff) | |
download | tcoin-1885cebc20732994279d23300ed4f437db7d584f.tar.gz |
Removing thousands separator whenever the output of tcoin is piped
Whenever the output of tcoin is piped, the thousands separator will not show up now.
-rw-r--r-- | tcoin.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/tcoin.cpp b/tcoin.cpp index 42660c6..31dd134 100644 --- a/tcoin.cpp +++ b/tcoin.cpp @@ -377,7 +377,7 @@ std::string get_username() return username; } -void num_stream_thousands_sep(std::ostringstream& ss, long long int const& amount, char sep=',') +void num_stream_thousands_sep(std::ostringstream& ss, long long int const& amount, char sep='\'') { if(amount == 0) { @@ -390,7 +390,7 @@ void num_stream_thousands_sep(std::ostringstream& ss, long long int const& amoun int residue = amount % 1000; bool residue_gte_100 = residue >= 100; bool residue_gte_10 = residue >= 10; - bool residue_gte_1 = residue >= 1;; + bool residue_gte_1 = residue >= 1; int num_residue_digits = residue_gte_100 + residue_gte_10 + residue_gte_1; @@ -438,6 +438,8 @@ void num_stream_thousands_sep(std::ostringstream& ss, long long int const& amoun ss << rev_str; } +bool stdout_is_piped = !isatty(fileno(stdout)); + std::string formatted_amount(long long int const& amount, char const* appended_chars_default = "", char const* appended_chars_singular = "") { std::ostringstream ss; @@ -452,7 +454,10 @@ std::string formatted_amount(long long int const& amount, char const* appended_c bool amount_has_single_digit_cents = !amount_is_integer && (abs_amount % 100 < 10); bool amount_has_double_digit_cents = !(amount_is_integer || amount_has_single_digit_cents); - num_stream_thousands_sep(ss, abs_amount/100); + if(stdout_is_piped) + ss << abs_amount/100; + else + num_stream_thousands_sep(ss, abs_amount/100); if(amount_has_single_digit_cents) ss << ".0"; |