/* START LIBRARY DESCRIPTION ********************************************* FLOAT.LIB Copyright (c) 2006, Avtech Electrosystems Ltd. DESCRIPTION: Functions that deal with strings and floating point numbers. SUPPORT LIB'S: END DESCRIPTION **********************************************************/ #include #include #include #include #include "globals.h" #include "string_utils.h" void Float_To_Text(int decimal_digits,float number_in, gchar ** text_out) { g_assert (*text_out == NULL); if (fabs(number_in)<1.1*smallest_allowed_number) { if (number_in<0.0) { *text_out = g_strdup_printf("-0.%0*d",decimal_digits,0); } else { *text_out = g_strdup_printf("0.%0*d",decimal_digits,0); } return; } *text_out = g_strdup_printf("%.*e", decimal_digits, number_in); } /*----------------------------------------------------------------------------------------------------------*/ gboolean String_is_it_numeric(char *parameter) { GRegex *numeric_regex = g_regex_new ( "\\s*[+-]?(\\d*\\.\\d+|\\d+(\\.\\d*)?)\\s*(e\\s*[+-]?\\d+)?\\s*", G_REGEX_CASELESS, 0, NULL); gboolean match = g_regex_match (numeric_regex, parameter, 0, NULL); g_regex_unref (numeric_regex); return match; }