如何修复 PlatformIO 中 mbed printf() 忽略小数的问题
问题:
你正在使用类似这样的代码
example.cpp
printf("%.2f\n", myFloat);在你的 mbed/PlatformIO 应用程序中,但它不是以 2 位小数打印 myFloat,而是始终以 6 位小数打印(如 0.000000)。
解决方案
mbed 默认使用 minimal-printf 库,该库配置为在微控制器上节省空间。因此,浮点最大小数支持默认禁用。为了以更多 flash 使用和更慢执行为代价获取所有 printf 功能,在 PlatformIO 项目的根目录中添加 mbed_app.json,其中包含 "target.printf_lib": "std":
mbed_app.json
{
"target_overrides": {
"*": {
"target.printf_lib": "std"
}
}
}有关更多详细信息和类似选项,请参见平台配置选项页面。
Check out similar posts by category:
C/C++, Mbed, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow