当前位置:网站首页>double转int精度丢失问题
double转int精度丢失问题
2022-07-06 09:14:00 【%xiao Q】
先来看一下精度丢失的现象:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a = 74.46;
int b = a * 100;
cout << "a: " << a << " b: " << b <<endl;
return 0;
}
结果:
解决:采用四舍五入的方法
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a = 74.46;
int b = round(a * 100);
cout << "a: " << a << " b: " << b << endl;
return 0;
}
结果:
边栏推荐
- Error reporting solution - io UnsupportedOperation: can‘t do nonzero end-relative seeks
- Invalid global search in idea/pychar, etc. (win10)
- 数据库高级学习笔记--SQL语句
- [C language foundation] 04 judgment and circulation
- Software testing and quality learning notes 3 -- white box testing
- QT creator specify editor settings
- AcWing 179.阶乘分解 题解
- Ansible practical Series II_ Getting started with Playbook
- 【博主推荐】SSM框架的后台管理系统(附源码)
- Invalid default value for 'create appears when importing SQL_ Time 'error reporting solution
猜你喜欢
AcWing 1298. Solution to Cao Chong's pig raising problem
Some problems in the development of unity3d upgraded 2020 VR
软件测试与质量学习笔记3--白盒测试
AcWing 1298.曹冲养猪 题解
In the era of DFI dividends, can TGP become a new benchmark for future DFI?
Learning question 1:127.0.0.1 refused our visit
Asp access Shaoxing tourism graduation design website
[recommended by bloggers] asp Net WebService background data API JSON (with source code)
How to build a new project for keil5mdk (with super detailed drawings)
Leetcode 461 Hamming distance
随机推荐
[BMZCTF-pwn] 11-pwn111111
[recommended by bloggers] C WinForm regularly sends email (with source code)
Swagger、Yapi接口管理服务_SE
Ansible实战系列三 _ task常用命令
Deoldify project problem - omp:error 15:initializing libiomp5md dll,but found libiomp5md. dll already initialized.
QT creator support platform
Solution: log4j:warn please initialize the log4j system properly
PyCharm中无法调用numpy,报错ModuleNotFoundError: No module named ‘numpy‘
数数字游戏
Are you monitored by the company for sending resumes and logging in to job search websites? Deeply convinced that the product of "behavior awareness system ba" has not been retrieved on the official w
When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page
frp内网穿透那些事
AI benchmark V5 ranking
[number theory] divisor
项目实战-后台员工信息管理(增删改查登录与退出)
Request object and response object analysis
Did you forget to register or load this tag 报错解决方法
JDBC principle
Introduction to the easy copy module
Number game