当前位置:网站首页>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;
}
结果:
边栏推荐
- AcWing 1294.樱花 题解
- Neo4j installation tutorial
- Why can't I use the @test annotation after introducing JUnit
- [Thesis Writing] how to write function description of jsp online examination system
- Copie maître - esclave MySQL, séparation lecture - écriture
- QT creator specifies dependencies
- Why is MySQL still slow to query when indexing is used?
- In the era of DFI dividends, can TGP become a new benchmark for future DFI?
- 數據庫高級學習筆記--SQL語句
- Machine learning -- census data analysis
猜你喜欢

Asp access Shaoxing tourism graduation design website

How to configure flymcu (STM32 serial port download software) is shown in super detail

When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page

QT creator specifies dependencies

MySQL主从复制、读写分离

Install mongdb tutorial and redis tutorial under Windows

MySQL主從複制、讀寫分離

Idea import / export settings file

Introduction and use of automatic machine learning framework (flaml, H2O)

neo4j安装教程
随机推荐
@Controller, @service, @repository, @component differences
Picture coloring project - deoldify
Ansible实战系列二 _ Playbook入门
[recommended by bloggers] asp Net WebService background data API JSON (with source code)
[BMZCTF-pwn] 11-pwn111111
Copie maître - esclave MySQL, séparation lecture - écriture
Base de données Advanced Learning Notes - - SQL statements
Principes JDBC
AI benchmark V5 ranking
连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
自动机器学习框架介绍与使用(flaml、h2o)
MySQL other hosts cannot connect to the local database
csdn-Markdown编辑器
CSDN markdown editor
QT creator support platform
Punctual atom stm32f103zet6 download serial port pin
MySQL completely uninstalled (windows, MAC, Linux)
Why is MySQL still slow to query when indexing is used?
One click extraction of tables in PDF
Ubuntu 20.04 安装 MySQL