当前位置:网站首页>【QT】qt加减乘除之后,保留小数点后两位
【QT】qt加减乘除之后,保留小数点后两位
2022-07-01 05:25:00 【路漫漫其远,吾求索】
【场景】
要实现10.00 - 5.00的结果等于5.00而不是等于5
因为正好减完之后是个整数,想要保留小数点后两位,直接保留是不行,即使是用double存数据
【方法】
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
double a = 10.00;
double b = 5.00;
double c = (a-b);
cout << setiosflags(ios::fixed) << setprecision(2) << c << endl;
}
MainWindow::~MainWindow()
{
delete ui;
}
结果

【补充】
也可以使用c的方法,直接%l2f保存小数点后两位
边栏推荐
- Rust hello-word
- C WPF uses dockpanel to realize screenshot box
- Chapitre d'apprentissage mongodb: Introduction à la première leçon après l'installation
- Actual combat: gateway api-2022.2.13
- Global and Chinese market of enterprise wireless LAN 2022-2028: Research Report on technology, participants, trends, market size and share
- 新手在挖财开通证券账户安全吗?
- SSGSSRCSR区别
- Tar command
- 如何选择导电滑环材料
- Worried about infringement? Must share copyrightless materials on the website. Don't worry about the lack of materials for video clips
猜你喜欢

Mongodb学习篇:安装后的入门第一课

Actual combat: gateway api-2022.2.13

Go learning notes (5) basic types and declarations (4)

如何创建一个根据进度改变颜色的进度条

Simple implementation of database connection pool

Dynamic verification of new form items in El form; El form verifies that the dynamic form V-IF does not take effect;

轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷

Speed regulation and stroke control based on Ti drv8424 driving stepper motor

Numeric amount plus comma; JS two methods of adding three digits and a comma to numbers; JS data formatting

Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
随机推荐
Unity 使用Sqlite
Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share
复制宝贝提示材质不能为空,如何解决?
In depth understanding of condition source code interpretation and analysis of concurrent programming
CentOS 7使用yum安装PHP7.0
LRU cache for leveldb source code analysis
busybox生成的东西
新手在挖财开通证券账户安全吗?
Understand several related problems in JVM - JVM memory layout, class loading mechanism, garbage collection
How to meet the requirements of source code confidentiality and source code security management
Redis数据库的部署及常用命令
Vmware workstation network card settings and three common network modes
eBPF Cilium实战(2) - 底层网络可观测性
Global and Chinese market of broadband amplifiers 2022-2028: Research Report on technology, participants, trends, market size and share
Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards
移动端常用解决方案
2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)
[data recovery in North Asia] a data recovery case of raid crash caused by hard disk drop during data synchronization of hot spare disk of RAID5 disk array
如何选择导电滑环材料
Cockroachdb: the resistant geo distributed SQL database paper reading notes