当前位置:网站首页>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;
}
结果:
边栏推荐
- Data dictionary in C #
- The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine
- Julia 1.6 1.7 common problem solving
- 项目实战-后台员工信息管理(增删改查登录与退出)
- QT creator support platform
- Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
- [C language foundation] 04 judgment and circulation
- 數據庫高級學習筆記--SQL語句
- How to configure flymcu (STM32 serial port download software) is shown in super detail
- Install MySQL for Ubuntu 20.04
猜你喜欢

Install mongdb tutorial and redis tutorial under Windows

Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘

自动机器学习框架介绍与使用(flaml、h2o)

Use dapr to shorten software development cycle and improve production efficiency

Deoldify project problem - omp:error 15:initializing libiomp5md dll,but found libiomp5md. dll already initialized.

Machine learning -- census data analysis

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

Why can't I use the @test annotation after introducing JUnit
![[number theory] divisor](/img/ec/036d7e76cc566c08d336444f2898e1.jpg)
[number theory] divisor

CSDN markdown editor
随机推荐
Did you forget to register or load this tag 报错解决方法
报错解决 —— io.UnsupportedOperation: can‘t do nonzero end-relative seeks
How to set up voice recognition on the computer with shortcut keys
02 staff information management after the actual project
How to build a new project for keil5mdk (with super detailed drawings)
Why can't I use the @test annotation after introducing JUnit
Generate PDM file from Navicat export table
Deoldify project problem - omp:error 15:initializing libiomp5md dll,but found libiomp5md. dll already initialized.
windows下同时安装mysql5.5和mysql8.0
Mysql 其他主机无法连接本地数据库
Classes in C #
Number game
Install mongdb tutorial and redis tutorial under Windows
引入了junit为什么还是用不了@Test注解
安装numpy问题总结
图像识别问题 — pytesseract.TesseractNotFoundError: tesseract is not installed or it‘s not in your path
QT creator shape
La table d'exportation Navicat génère un fichier PDM
Solution: log4j:warn please initialize the log4j system properly
【博主推荐】C# Winform定时发送邮箱(附源码)