]> Dogcows Code - chaz/homebank/blobdiff - src/hb-misc.c
import homebank-5.1.7
[chaz/homebank] / src / hb-misc.c
index b0e7600de8e263e92af55ac5ec31eba5d69a00fa..179e213ada4216026bbf1872be0a74a306a70fe0 100644 (file)
@@ -1,5 +1,5 @@
 /*  HomeBank -- Free, easy, personal accounting for everyone.
- *  Copyright (C) 1995-2016 Maxime DOYEN
+ *  Copyright (C) 1995-2018 Maxime DOYEN
  *
  *  This file is part of HomeBank.
  *
@@ -52,8 +52,7 @@ double hb_amount_round(const double x, unsigned int digits)
 
 gdouble hb_amount_to_euro(gdouble amount)
 {
-       return hb_amount_round((amount / PREFS->euro_value), 2);
-       //return hb_amount_round((amount * PREFS->euro_value), PREFS.minor_cur->frac_digits);
+       return hb_amount_round((amount * PREFS->euro_value), PREFS->minor_cur.frac_digits);
 }
 
 
@@ -224,14 +223,16 @@ gdouble monval;
        }
        else
        {
+               monval = hb_amount_base(value, kcur);
+               monval = hb_amount_to_euro(monval);
                cur = &PREFS->minor_cur;
-               monval = hb_amount_to_euro(value);
                g_ascii_formatd(formatd_buf, outlen, cur->format, monval);
                hb_str_formatd(outstr, outlen, formatd_buf, cur, TRUE);
        }
 
 }
 
+
 void hb_strfmon_int(gchar *outstr, gint outlen, gdouble value, guint32 kcur, gboolean minor)
 {
 gchar formatd_buf[outlen];
@@ -250,8 +251,9 @@ gdouble monval;
        }
        else
        {
+               monval = hb_amount_base(value, kcur);
+               monval = hb_amount_to_euro(monval);
                cur = &PREFS->minor_cur;
-               monval = hb_amount_to_euro(value);
                g_ascii_formatd(formatd_buf, outlen, cur->format, monval);
                hb_str_formatd(outstr, outlen, formatd_buf, cur, TRUE);
        }
@@ -271,7 +273,7 @@ gdouble monval;
                if(cur != NULL)
                {
                        monval = hb_amount_round(value, cur->frac_digits);
-                       g_ascii_formatd(formatd_buf, outlen, "%0.f", monval);
+                       g_ascii_formatd(formatd_buf, outlen, "%.2f", monval);
                        hb_str_formatd(outstr, outlen, formatd_buf, cur, TRUE);
                }
        }
@@ -279,7 +281,7 @@ gdouble monval;
        {
                cur = &PREFS->minor_cur;
                monval = hb_amount_to_euro(value);
-               g_ascii_formatd(formatd_buf, outlen, "%0.f", monval);
+               g_ascii_formatd(formatd_buf, outlen, "%.2f", monval);
                hb_str_formatd(outstr, outlen, formatd_buf, cur, TRUE);
        }
 
@@ -287,7 +289,6 @@ gdouble monval;
 }
 
 
-
 gchar *get_normal_color_amount(gdouble value)
 {
 gchar *color = NULL;
@@ -453,7 +454,52 @@ gchar *d = str;
 }
 
 
-/*static void strip_extra_spaces(char* str) {
+gchar *hb_string_copy_jsonpair(gchar *dst, gchar *str)
+{
+
+       while( *str!='\0' )
+       {
+               if( *str=='}' )
+                       break;
+
+               if( *str==',' )
+               {
+                       *dst = '\0';
+                       return str + 1;
+               }
+
+               if( *str!='{' && *str!='\"' )
+               {
+                       *dst++ = *str;
+               }
+               str++;
+       }
+       *dst = '\0';
+       return NULL;
+}
+
+
+void hb_string_inline(gchar *str)
+{
+gchar *s = str;
+gchar *d = str;
+
+       if(str)
+       {
+               while( *s )
+               {
+                       if( !(*s==' ' || *s=='\t' || *s=='\n' || *s=='\r') )
+                       {
+                               *d++ = *s;
+                       }
+                       s++;
+               }
+               *d = 0;
+       }
+}
+
+
+/*void strip_extra_spaces(char* str) {
   int i,x;
   for(i=x=1; str[i]; ++i)
     if(!isspace(str[i]) || (i>0 && !isspace(str[i-1])))
@@ -592,7 +638,7 @@ guint32 julian = 0;
 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
 
 
-gchar *hb_util_filename_new_with_extension(gchar *filename, const gchar *extension)
+gchar *hb_filename_new_with_extension(gchar *filename, const gchar *extension)
 {
 gchar *lastdot, *fwe;
 gchar *newfilename;
@@ -696,7 +742,8 @@ GDate date;
                                g_date_get_month(&date),
                                g_date_get_year(&date)
                                );
-               }       
+               }
+               break;
                default:
                        g_sprintf(outstr, "%04d/%02d/%02d",
                                g_date_get_year(&date),
This page took 0.020541 seconds and 4 git commands to generate.