summaryrefslogtreecommitdiff
path: root/string_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'string_utils.c')
-rw-r--r--string_utils.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/string_utils.c b/string_utils.c
index 502e2a7..33e830e 100644
--- a/string_utils.c
+++ b/string_utils.c
@@ -38,7 +38,7 @@ gboolean String_is_it_numeric(char *parameter)
void String_Parameter_To_Text(float Float_To_Convert, int significant_digits,
- char *start_string,char *units,gchar **LCD_string,int show_plus_sign)
+ char *start_string,char *units,gchar **LCD_string,int show_plus_sign, int width_of_column)
{
gchar *floating_val = NULL;
gchar *unit_mult = NULL; /* units multiplier, eg. M, k, u */
@@ -118,10 +118,13 @@ void String_Parameter_To_Text(float Float_To_Convert, int significant_digits,
/* put in the new decimal point */
out_gstr = g_string_append_c (out_gstr, '.');
+ int space_left = width_of_column - strlen(out_gstr->str) - strlen (unit_mult) - strlen (units);
+
/* copy the rest of the digits */
- for (i=shift_decimal_by+1+decimal_location; digits_so_far<significant_digits; ++i) {
+ for (i=shift_decimal_by+1+decimal_location; (digits_so_far<significant_digits) && (space_left>0); ++i) {
out_gstr = g_string_append_c (out_gstr, floating_val[i]);
++digits_so_far;
+ space_left = width_of_column - strlen(out_gstr->str) - strlen (unit_mult) - strlen (units);
/* leave space for minus sign, decimal point, and extra digit on the end too */
}