From b1f691f2deb0b59c6e237241e1995c5d95f37ffa Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Thu, 17 Aug 2017 15:27:52 -0400 Subject: Introduce ftoa() as a replacement for the %g format specifier Not all platforms support printing floats, this is a more portable (if uglier) way. --- misc.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'misc.c') diff --git a/misc.c b/misc.c index bb9019e..ed31acb 100644 --- a/misc.c +++ b/misc.c @@ -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. */ -- cgit v1.1