当前位置:网站首页>[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
边栏推荐
- Redis数据库的部署及常用命令
- How to meet the requirements of source code confidentiality and source code security management
- Programmers dig "holes" to get rich: if they find a loophole, they will be rewarded 12.72 million yuan
- Chapitre d'apprentissage mongodb: Introduction à la première leçon après l'installation
- eBPF Cilium实战(2) - 底层网络可观测性
- SSM的教务管理系统(免费源码获取)
- Design and application of immutable classes
- Cockroachdb: the resistant geo distributed SQL database paper reading notes
- Summary of common components of applet
- Some common commands of podman
猜你喜欢

ssm+mysql二手交易网站(论文+源码获取链接)

Thread process foundation of JUC

eBPF Cilium实战(2) - 底层网络可观测性

A little assistant for teenagers' physiological health knowledge based on wechat applet (free source code + project introduction + operation introduction + operation screenshot + Thesis)

LevelDB源码分析之memtable

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

C WPF uses dockpanel to realize screenshot box

Lock free concurrency of JUC (leguan lock)

TypeORM 框架

教务管理系统(免费源码获取)
随机推荐
[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
Mongodb学习篇:安装后的入门第一课
tar命令
JDBC常见面试题
数据库连接池的简单实现
Tar command
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
Floweable source code annotation (40) class delegation
rust猜数字游戏
Common solutions for mobile terminals
Is it safe for a novice to open a securities account?
Some common commands of podman
ssm+mysql二手交易网站(论文+源码获取链接)
Idea start view project port
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Boot + jsp University Community Management System (with source Download Link)
eBPF Cilium实战(2) - 底层网络可观测性
激活函数简述
el-form表单新增表单项动态校验;el-form校验动态表单v-if不生效;
2022.6.30-----leetcode.1175