当前位置:网站首页>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 :
边栏推荐
- [蓝桥杯2021初赛] 砝码称重
- Pytorch基础
- L2-001 紧急救援 (25 分)
- QT creator specifies dependencies
- Ansible practical Series II_ Getting started with Playbook
- JDBC principle
- Dotnet replaces asp Net core's underlying communication is the IPC Library of named pipes
- MySQL completely uninstalled (windows, MAC, Linux)
- Basic use of redis
- AcWing 242. A simple integer problem (tree array + difference)
猜你喜欢

error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead

LeetCode #461 汉明距离
![[蓝桥杯2017初赛]方格分割](/img/e9/e49556d0867840148a60ff4906f78e.png)
[蓝桥杯2017初赛]方格分割

Kept VRRP script, preemptive delay, VIP unicast details

Vs2019 use wizard to generate an MFC Application

Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path

Solve the problem of installing failed building wheel for pilot

Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.

QT creator specify editor settings

MySQL master-slave replication, read-write separation
随机推荐
[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP
LeetCode #461 汉明距离
double转int精度丢失问题
Dotnet replaces asp Net core's underlying communication is the IPC Library of named pipes
L2-006 树的遍历 (25 分)
牛客Novice月赛40
Number game
Machine learning -- census data analysis
连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
Aborted connection 1055898 to db:
Learning question 1:127.0.0.1 refused our visit
Library function -- (continuous update)
Machine learning notes week02 convolutional neural network
vs2019 第一个MFC应用程序
Why can't STM32 download the program
软件测试-面试题分享
Software testing and quality learning notes 3 -- white box testing
Solution: log4j:warn please initialize the log4j system properly
Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.
保姆级出题教程