当前位置:网站首页>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;
}
结果:
边栏推荐
- Other new features of mysql18-mysql8
- The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine
- 【博主推荐】C#MVC列表实现增删改查导入导出曲线功能(附源码)
- 机器学习--人口普查数据分析
- Leetcode 461 Hamming distance
- Ansible实战系列三 _ task常用命令
- Postman Interface Association
- 數據庫高級學習筆記--SQL語句
- Install MySQL for Ubuntu 20.04
- Esp8266 at+cipstart= "", "", 8080 error closed ultimate solution
猜你喜欢
【博主推荐】C#生成好看的二维码(附源码)
[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)
学习问题1:127.0.0.1拒绝了我们的访问
Other new features of mysql18-mysql8
QT creator runs the Valgrind tool on external applications
Invalid global search in idea/pychar, etc. (win10)
Did you forget to register or load this tag
Idea import / export settings file
Esp8266 at+cipstart= "", "", 8080 error closed ultimate solution
Dotnet replaces asp Net core's underlying communication is the IPC Library of named pipes
随机推荐
AcWing 1294. Cherry Blossom explanation
AcWing 1298. Solution to Cao Chong's pig raising problem
学习问题1:127.0.0.1拒绝了我们的访问
记一次某公司面试题:合并有序数组
Ansible practical Series II_ Getting started with Playbook
QT creator create button
Swagger, Yapi interface management service_ SE
QT creator shape
Database advanced learning notes -- SQL statement
MySQL完全卸载(Windows、Mac、Linux)
Ubuntu 20.04 安装 MySQL
Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
neo4j安装教程
Why is MySQL still slow to query when indexing is used?
Software testing - interview question sharing
Request object and response object analysis
机器学习--人口普查数据分析
QT creator design user interface
Julia 1.6 1.7 common problem solving
【博主推荐】asp.net WebService 后台数据API JSON(附源码)