【发布时间】:2014-06-12 15:30:36
【问题描述】:
我正在构建一个应用程序来显示您已经走了多少英里,我希望它有 3 个小数位。例如,“0.435 英里”。我试过下面的代码:
static char stopwatch_miles[50];
snprintf(stopwatch_miles, sizeof(stopwatch_miles), "%.3f miles", num_miles);
text_layer_set_text(miles_layer, stopwatch_miles);
num_miles 是一个计算的浮点变量。但是,Pebble 在 1.13 中不推荐使用 snprintf 中的浮点数。有简单的解决方法吗?也许使用int,在我的数学运算前将其乘以 1000 并在格式中添加小数位?
【问题讨论】:
标签: c pebble-sdk