summaryrefslogtreecommitdiff
path: root/string_utils.c
diff options
context:
space:
mode:
authorroot <root@avtech.domain.avtechpulse.com>1999-12-31 19:31:45 -0500
committerroot <root@avtech.domain.avtechpulse.com>1999-12-31 19:31:45 -0500
commit754eb84c5c7e10c9b6c4060e230300b090a95bee (patch)
tree2d6ce8c815814e8ab25a8390dab5ec3c2e2b256f /string_utils.c
parent1d11fc9a26611ac5af7b46241125d10f2b79c2cf (diff)
better calculation of space for significant digits
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 */
}