From: Bert Vermeulen Date: Mon, 4 Feb 2013 12:36:23 +0000 (+0100) Subject: properly deal with decimals X-Git-Tag: dsupstream~269 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d5a669a9e0319531595a8a45b6c21f0c316a24f1;p=libsigrok.git properly deal with decimals --- diff --git a/strutil.c b/strutil.c index f22cd59c..ad9f6497 100644 --- 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... */