c++ int转double保留两位小数
时间: 2023-09-23 08:11:44 浏览: 164
保留两位小数
在C/C++中,将int类型转换为double并保留两位小数可以通过以下几种方法实现。
方法1:使用sprintf函数
```
int num = 12345;
char buffer<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [C++ double转string并保留2位小数的两种方法](https://blog.csdn.net/qq_33236491/article/details/108321230)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [C/C++ int运算结果转float/double 保留小数](https://blog.csdn.net/u013288190/article/details/127119183)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文