From 478534343c42e53460de85b596b55bdecd4115e4 Mon Sep 17 00:00:00 2001 From: login Date: Thu, 23 Nov 2023 07:54:57 +0000 Subject: Fixed bug in thousands separator When the input is 0, the thousands-separator function was sending nothing. Now, it sends 0. --- tcoin.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tcoin.cpp b/tcoin.cpp index e3bde74..42660c6 100644 --- a/tcoin.cpp +++ b/tcoin.cpp @@ -379,6 +379,12 @@ std::string get_username() void num_stream_thousands_sep(std::ostringstream& ss, long long int const& amount, char sep=',') { + if(amount == 0) + { + ss << 0; + return; + } + std::ostringstream rev; long long int reduced_amount = amount/1000; int residue = amount % 1000; @@ -388,8 +394,8 @@ void num_stream_thousands_sep(std::ostringstream& ss, long long int const& amoun int num_residue_digits = residue_gte_100 + residue_gte_10 + residue_gte_1; - int mini_reduced_amount = amount/10; - int mini_residue = amount % 10; + int mini_reduced_amount = residue/10; + int mini_residue = residue % 10; do { @@ -415,8 +421,8 @@ void num_stream_thousands_sep(std::ostringstream& ss, long long int const& amoun residue_gte_1 = residue >= 1; num_residue_digits = residue_gte_100 + residue_gte_10 + residue_gte_1; - mini_reduced_amount = reduced_amount/10; - mini_residue = reduced_amount % 10; + mini_reduced_amount = residue/10; + mini_residue = residue % 10; reduced_amount = reduced_amount/1000; } while(reduced_amount > 0); -- cgit 1.4.1-2-gfad0