summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@fedora-arm.domain.avtechpulse.com>1999-12-31 19:29:55 -0500
committerroot <root@fedora-arm.domain.avtechpulse.com>1999-12-31 19:29:55 -0500
commit8003bf319954665b9269457be943ca01bb8c440e (patch)
tree1632df86b4fd73be92b43f06c091deab0be28852
parentf68e6dc228980e2d980c6774cda3db120bd5e17b (diff)
fix significant digit handling
-rw-r--r--string_utils.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/string_utils.c b/string_utils.c
index e3cb4f8..a5f6e6f 100644
--- a/string_utils.c
+++ b/string_utils.c
@@ -42,14 +42,12 @@ gboolean String_is_it_numeric(char *parameter)
void String_Parameter_To_Text(float Float_To_Convert, int significant_digits,
char *start_string,char *units,char *LCD_string,int show_plus_sign)
{
- // FIXME - crappy string func
gchar *floating_val = NULL;
gchar *unit_mult = NULL; /* units multiplier, eg. M, k, u */
int i; /* just a counter */
int shift_decimal_by; /* if the exponent isn't a multiple of 3, the decimal point will be moved */
int decimal_location; /* where the decimal is in the number string */
- int chars_processed; /* how many characters are in the parsed number string so far */
int exponent_val; /* the exponent, in integer form */
@@ -74,21 +72,20 @@ void String_Parameter_To_Text(float Float_To_Convert, int significant_digits,
/* -- COPY FIRST ONE OR TWO CHARACTERS -- */
if (floating_val[0]=='-') { /* if it's negative ... */
decimal_location=2; /* decimal at position two (e.g.: -2.23e-9) */
- chars_processed=2; /* two characters so far (e.g.: -2) */
out_gstr = g_string_append_c (out_gstr, '-'); /* copy minus sign */
out_gstr = g_string_append_c (out_gstr, floating_val[1]); /* copy first digit */
} else if (show_plus_sign==YES) { /* if it's positive and plus sign required ... */
decimal_location=1; /* decimal at position one (e.g.: 2.23e-9) */
- chars_processed=2; /* two characters so far (e.g.: +2) */
out_gstr = g_string_append_c (out_gstr, '+'); /* copy minus sign */
out_gstr = g_string_append_c (out_gstr, floating_val[0]); /* copy first digit */
} else { /* if it's positive and plus sign not required ... */
decimal_location=1; /* decimal at position one (e.g.: 2.23e-9) */
- chars_processed=1; /* one character so far (e.g.: 2) */
out_gstr = g_string_append_c (out_gstr, floating_val[0]); /* copy first digit */
}
+ int digits_so_far = 1;
+
/* -- FIND EXPONENT -- */
/* find how much the decimal has to be moved, by examining the exponent in the string and */
/* modding it by 3 */
@@ -123,17 +120,16 @@ void String_Parameter_To_Text(float Float_To_Convert, int significant_digits,
/* move the digits that will come before the decimal */
for (i=decimal_location; i<decimal_location+shift_decimal_by; ++i) {
out_gstr = g_string_append_c (out_gstr, floating_val[1+i]);
- ++chars_processed;
+ ++digits_so_far;
}
/* put in the new decimal point */
out_gstr = g_string_append_c (out_gstr, '.');
- ++chars_processed;
/* copy the rest of the digits */
- for (i=shift_decimal_by+1+decimal_location; i<significant_digits+3; ++i) {
+ for (i=shift_decimal_by+1+decimal_location; digits_so_far<significant_digits; ++i) {
out_gstr = g_string_append_c (out_gstr, floating_val[i]);
- ++chars_processed;
+ ++digits_so_far;
/* leave space for minus sign, decimal point, and extra digit on the end too */
}
@@ -142,8 +138,6 @@ void String_Parameter_To_Text(float Float_To_Convert, int significant_digits,
strcat(LCD_string,out_gstr->str);
g_string_free (out_gstr, TRUE);
- LCD_string[strlen(LCD_string)-1]=0; /* remove extra digit */
-
/* -- CHECK FOR TERMINATING DECIMAL POINT -- */
if (LCD_string[strlen(LCD_string)-1]=='.') {
LCD_string[strlen(LCD_string)-1]=0;