From 1885cebc20732994279d23300ed4f437db7d584f Mon Sep 17 00:00:00 2001 From: login Date: Sat, 25 Nov 2023 19:38:14 +0000 Subject: 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. --- tcoin.cpp | 11 ++++++++--- 1 file 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"; -- cgit 1.4.1-2-gfad0