当前位置:网站首页>[QT] QT after addition, subtraction, multiplication and division, two decimal places are reserved
[QT] QT after addition, subtraction, multiplication and division, two decimal places are reserved
2022-07-01 05:36:00 【There is a long way to go】
【 scene 】
To achieve 10.00 - 5.00 The result is equal to 5.00 Instead of being equal to 5
Because it is an integer just after subtraction , Want to keep two decimal places , You can't keep it directly , Even with double Save the data
【 Method 】
#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;
}
result

【 Add 】
You can also use c Methods , direct %l2f Save two decimal places
边栏推荐
- printk 调试总结
- Introduction of 3D Modeling and Processing Software Liu Ligang, Chinese University of Science and Technology
- Using nocalhost to develop microservice application on rainbow
- Boot + jsp University Community Management System (with source Download Link)
- Redis数据库的部署及常用命令
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- Txncoordsender of cockroachdb distributed transaction source code analysis
- Ssm+mysql second-hand trading website (thesis + source code access link)
- Speed regulation and stroke control based on Ti drv8424 driving stepper motor
- Is there any good website or software for learning programming? [introduction to programming]?
猜你喜欢

Understand several related problems in JVM - JVM memory layout, class loading mechanism, garbage collection

C# wpf 使用DockPanel实现截屏框

实战:redux的基本使用

基于微信小程序的青少年生理健康知识小助手(免费获取源码+项目介绍+运行介绍+运行截图+论文)

Txncoordsender of cockroachdb distributed transaction source code analysis

Memtable for leveldb source code analysis

Day 05 - file operation function
Educational administration management system of SSM (free source code)

Vmware workstation network card settings and three common network modes

Deeply understand the underlying implementation principle of countdownlatch in concurrent programming
随机推荐
Day 05 - file operation function
Introduction of 3D Modeling and Processing Software Liu Ligang, Chinese University of Science and Technology
Use and principle of AQS related implementation classes
Learn the customization and testing of fpga---ram IP from the bottom structure
busybox生成的东西
SSM的教务管理系统(免费源码获取)
HDU - 1024 Max Sum Plus Plus(DP)
El cascade echo failed; El cascader does not echo
Practice of combining rook CEPH and rainbow, a cloud native storage solution
如何创建一个根据进度改变颜色的进度条
Programmers dig "holes" to get rich: if they find a loophole, they will be rewarded 12.72 million yuan
了解 JVM 中几个相关问题 — JVM 内存布局、类加载机制、垃圾回收
And search: the suspects (find the number of people related to the nth person)
Youqitong [vip] v3.7.2022.0106 official January 22 Edition
Memtable for leveldb source code analysis
Printk debugging summary
Set集合詳細講解
Flutter can refresh data every time the interface comes in
CockroachDB: The Resilient Geo-Distributed SQL Database 论文阅读笔记
CentOS 7使用yum安装PHP7.0