【Pebble】atofを使うとビルドできなくなる問題の対処法
atof使うとビルドが通らないので自分で作ります。
atof2.h
float atof2(const char* s);
atof2.c
float atof2(const char* s){ float rez = 0, fact = 1; if (*s == '-'){ s++; fact = -1; }; for (int point_seen = 0; *s; s++){ if (*s == '.'){ point_seen = 1; continue; }; int d = *s - '0'; if (d >= 0 && d <= 9){ if (point_seen) fact /= 10.0f; rez = rez * 10.0f + (float)d; }; }; return rez * fact; };
これをインクルードしてatof2(cstring)すればビルド通るようになります。
尚、Floatをcstringにしようとしても
Floating point is not supported by snprintf
が出るので、その時は
int d1 = resultFloat; float f2 = resultFloat - d1; int d2 = trunc(f2 * 100); snprintf(resultString, sizeof(resultString), "%d.%02d", d1, d2);
みたいにして回避してやります。