当前位置:网站首页>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;
}
结果:
边栏推荐
- Solve the problem of installing failed building wheel for pilot
- NPM an error NPM err code enoent NPM err syscall open
- FRP intranet penetration
- 基于apache-jena的知识问答
- Why can't I use the @test annotation after introducing JUnit
- 解决安装Failed building wheel for pillow
- Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis
- In the era of DFI dividends, can TGP become a new benchmark for future DFI?
- Record a problem of raspberry pie DNS resolution failure
- Installation and use of MySQL under MySQL 19 Linux
猜你喜欢
Why is MySQL still slow to query when indexing is used?
Invalid global search in idea/pychar, etc. (win10)
Navicat 導出錶生成PDM文件
Solution: log4j:warn please initialize the log4j system properly
Classes in C #
Cookie setting three-day secret free login (run tutorial)
Install mongdb tutorial and redis tutorial under Windows
Other new features of mysql18-mysql8
Leetcode 461 Hamming distance
[C language foundation] 04 judgment and circulation
随机推荐
Why is MySQL still slow to query when indexing is used?
LeetCode #461 汉明距离
QT creator test
MySQL other hosts cannot connect to the local database
QT creator uses Valgrind code analysis tool
【博主推荐】asp.net WebService 后台数据API JSON(附源码)
Esp8266 at+cipstart= "", "", 8080 error closed ultimate solution
There are three iPhone se 2022 models in the Eurasian Economic Commission database
Ansible实战系列二 _ Playbook入门
一键提取pdf中的表格
What does BSP mean
The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine
Why can't I use the @test annotation after introducing JUnit
QT creator design user interface
Install mongdb tutorial and redis tutorial under Windows
【博主推荐】C# Winform定时发送邮箱(附源码)
1. Mx6u learning notes (VII): bare metal development (4) -- master frequency and clock configuration
Why can't STM32 download the program
How to build a new project for keil5mdk (with super detailed drawings)
The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine