当前位置:网站首页>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;
}
结果:
边栏推荐
- Error connecting to MySQL database: 2059 - authentication plugin 'caching_ sha2_ The solution of 'password'
- 解决安装Failed building wheel for pillow
- [recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)
- 02 staff information management after the actual project
- 图片上色项目 —— Deoldify
- 图像识别问题 — pytesseract.TesseractNotFoundError: tesseract is not installed or it‘s not in your path
- Basic use of redis
- Installation and use of MySQL under MySQL 19 Linux
- 引入了junit为什么还是用不了@Test注解
- 虚拟机Ping通主机,主机Ping不通虚拟机
猜你喜欢

AI benchmark V5 ranking

AcWing 1298. Solution to Cao Chong's pig raising problem

A trip to Macao - > see the world from a non line city to Macao

图像识别问题 — pytesseract.TesseractNotFoundError: tesseract is not installed or it‘s not in your path

QT creator test

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

Classes in C #

Swagger, Yapi interface management service_ SE

Navicat 導出錶生成PDM文件

解决安装Failed building wheel for pillow
随机推荐
What does BSP mean
连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
Some notes of MySQL
记某公司面试算法题:查找一个有序数组某个数字出现的次数
[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)
Solution: log4j:warn please initialize the log4j system properly
[BMZCTF-pwn] 11-pwn111111
软件测试与质量学习笔记3--白盒测试
[AGC009D]Uninity
Copie maître - esclave MySQL, séparation lecture - écriture
QT creator test
虚拟机Ping通主机,主机Ping不通虚拟机
SSM整合笔记通俗易懂版
JDBC原理
Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
How to configure flymcu (STM32 serial port download software) is shown in super detail
【博主推荐】SSM框架的后台管理系统(附源码)
windows下同时安装mysql5.5和mysql8.0
01项目需求分析 (点餐系统)
1. Mx6u learning notes (VII): bare metal development (4) -- master frequency and clock configuration