当前位置:网站首页>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 :
边栏推荐
猜你喜欢
AI benchmark V5 ranking
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
How to build a new project for keil5mdk (with super detailed drawings)
Cookie setting three-day secret free login (run tutorial)
打开浏览器的同时会在主页外同时打开芒果TV,抖音等网站
软件测试与质量学习笔记3--白盒测试
Did you forget to register or load this tag
Basic use of redis
neo4j安装教程
学习问题1:127.0.0.1拒绝了我们的访问
随机推荐
DICOM: Overview
QT creator uses Valgrind code analysis tool
Picture coloring project - deoldify
Learn winpwn (3) -- sEH from scratch
Rhcsa certification exam exercise (configured on the first host)
[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP
QT creator custom build process
double转int精度丢失问题
Why can't I use the @test annotation after introducing JUnit
Ansible实战系列一 _ 入门
AcWing 179. Factorial decomposition problem solution
JDBC原理
Basic use of redis
Armv8-a programming guide MMU (2)
Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
Summary of numpy installation problems
Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
Redis的基础使用
自动机器学习框架介绍与使用(flaml、h2o)
Pytorch基础