print float overly simple

Run Settings
LanguageC++
Language Version
Run Command
#include <stdio.h> #include <stdint.h> void print_float_value(uint64_t v, size_t i, bool prev_p) { if(i >= 4 && v <= 0) { return; } else { bool p = prev_p | (v % 10 != 0); print_float_value(v / 10, i + 1, p); if(i >= 3 || p) { if(i == 2) { putchar('.'); } putchar('0' + v % 10); } } } // Note: This does not work for doubles larger then "uint64_t max / 1000" void print_float(double v) { if(v < 0) { putchar('-'); v = -v; } print_float_value(v * 1000 + 0.5, 0, false); } int main() { print_float(-9.1235); putchar('\n'); print_float(0); putchar('\n'); print_float(5561134); putchar('\n'); print_float(20.05); putchar('\n'); print_float(700.0); putchar('\n'); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines