]> sigrok.org Git - libsigrok.git/commitdiff
properly deal with decimals
authorBert Vermeulen <redacted>
Mon, 4 Feb 2013 12:36:23 +0000 (13:36 +0100)
committerBert Vermeulen <redacted>
Sun, 10 Feb 2013 16:06:56 +0000 (17:06 +0100)
strutil.c

index f22cd59c27b380e173d0477eef5bd156f8a7b126..ad9f64974fe8c477df34f9749700ad1f11bddd1e 100644 (file)
--- a/strutil.c
+++ b/strutil.c
@@ -165,8 +165,8 @@ SR_API char *sr_period_string(uint64_t frequency)
  */
 SR_API char *sr_voltage_string(struct sr_rational *voltage)
 {
-       char *o;
        int r;
+       char *o;
 
        if (!(o = g_try_malloc0(30 + 1))) {
                sr_err("%s: o malloc failed", __func__);
@@ -178,7 +178,7 @@ SR_API char *sr_voltage_string(struct sr_rational *voltage)
        else if (voltage->q == 1)
                r = snprintf(o, 30, "%" PRIu64 "V", voltage->p);
        else
-               r = -1;
+               r = snprintf(o, 30, "%gV", (float)voltage->p / (float)voltage->q);
 
        if (r < 0) {
                /* Something went wrong... */