当前位置:网站首页>Double to int precision loss
Double to int precision loss
2022-07-06 11:25:00 【%xiao Q】
Let's first look at the phenomenon of precision loss :
#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;
}
result :
solve : Use rounding method
#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;
}
result :
边栏推荐
- ImportError: libmysqlclient. so. 20: Cannot open shared object file: no such file or directory solution
- Pytorch基础
- Solution: log4j:warn please initialize the log4j system properly
- QT creator specifies dependencies
- Ansible实战系列二 _ Playbook入门
- JDBC principle
- Julia 1.6 1.7 common problem solving
- Django运行报错:Error loading MySQLdb module解决方法
- 一键提取pdf中的表格
- MySQL master-slave replication, read-write separation
猜你喜欢
图片上色项目 —— Deoldify
[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP
Machine learning notes week02 convolutional neural network
One click extraction of tables in PDF
02 staff information management after the actual project
Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.
Software testing and quality learning notes 3 -- white box testing
Django running error: error loading mysqldb module solution
vs2019 使用向导生成一个MFC应用程序
Leetcode 461 Hamming distance
随机推荐
Introduction to the easy copy module
Ansible实战系列一 _ 入门
Library function -- (continuous update)
Remember the interview algorithm of a company: find the number of times a number appears in an ordered array
解决安装Failed building wheel for pillow
Integration test practice (1) theoretical basis
Rhcsa certification exam exercise (configured on the first host)
[Thesis Writing] how to write function description of jsp online examination system
记一次某公司面试题:合并有序数组
QT creator runs the Valgrind tool on external applications
double转int精度丢失问题
Copie maître - esclave MySQL, séparation lecture - écriture
L2-006 树的遍历 (25 分)
Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
MySQL other hosts cannot connect to the local database
JDBC原理
[蓝桥杯2017初赛]包子凑数
AcWing 1298.曹冲养猪 题解
About string immutability
Face recognition_ recognition