UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


guides:fixedpoint

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
guides:fixedpoint [2011/07/17 18:03] – created fsphilguides:fixedpoint [2011/07/17 19:28] (current) – [Fixed-point integer to String] fsphil
Line 59: Line 59:
 </code> </code>
  
-===== Fixed-point integer to String =====+===== Fixed-point integer to string =====
  
 +<code c>#include <stdio.h>
 +#include <stdint.h>
  
 +const char *fptostr(char *s, size_t n, int32_t value, int8_t dp)
 +{
 +        int32_t sh;
 +        char i, neg;
 +
 +        neg = value < 0;
 +        if(neg) value = -value;
 +
 +        for(sh = 1, i = 0; i < dp; i++) sh *= 10;
 +
 +        snprintf(s, n, "%s%u.%0*u",
 +                (neg ? "-" : ""),
 +                value / sh, dp,
 +                value % sh);
 +
 +        return(s);
 +}
 +</code>
guides/fixedpoint.1310925820.txt.gz · Last modified: 2011/07/17 18:03 by fsphil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki