diff options
| author | Franklin Wei <me@fwei.tk> | 2017-08-17 15:27:52 -0400 |
|---|---|---|
| committer | Franklin Wei <franklin@rockbox.org> | 2020-12-07 19:27:19 -0500 |
| commit | b1f691f2deb0b59c6e237241e1995c5d95f37ffa (patch) | |
| tree | 499df3c5baf7fbb9943909f0eb4d48db386b444c /misc.c | |
| parent | b4b86bbdbeb99c9fd9cfa6b61454047eb5e8fe20 (diff) | |
| download | puzzles-b1f691f2deb0b59c6e237241e1995c5d95f37ffa.zip puzzles-b1f691f2deb0b59c6e237241e1995c5d95f37ffa.tar.gz puzzles-b1f691f2deb0b59c6e237241e1995c5d95f37ffa.tar.bz2 puzzles-b1f691f2deb0b59c6e237241e1995c5d95f37ffa.tar.xz | |
Introduce ftoa() as a replacement for the %g format specifier
Not all platforms support printing floats, this is a more
portable (if uglier) way.
Diffstat (limited to 'misc.c')
| -rw-r--r-- | misc.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -402,6 +402,12 @@ void copy_left_justified(char *buf, size_t sz, const char *str) buf[sz - 1] = 0; } +/* another kludge for platforms without %g support in *printf() */ +int ftoa(char *buf, float f) +{ + return sprintf(buf, "%d.%06d", (int)f, abs((int)((f - (int)f)*1e6))); +} + /* Returns a dynamically allocated label for a generic button. * Game-specific buttons should go into the `label' field of key_label * instead. */ |