当前位置:网站首页>[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
边栏推荐
- Leetcode top 100 questions 1 Sum of two numbers
- Flutter 实现每次进来界面都刷新数据
- A little assistant for teenagers' physiological health knowledge based on wechat applet (free source code + project introduction + operation introduction + operation screenshot + Thesis)
- Introduction of 3D Modeling and Processing Software Liu Ligang, Chinese University of Science and Technology
- Trust guessing numbers game
- Multi table operation - foreign key cascade operation
- Use and principle of reentrantlock
- CockroachDB: The Resilient Geo-Distributed SQL Database 论文阅读笔记
- Tar command
- 从底层结构开始学习FPGA----RAM IP的定制与测试
猜你喜欢

rust猜数字游戏

2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)

Set set detailed explanation

Summary of common components of applet

Memtable for leveldb source code analysis
![[RootersCTF2019]babyWeb](/img/b4/aa8f8e107a9dacbace72d4717b1834.png)
[RootersCTF2019]babyWeb

Simple implementation of database connection pool

从底层结构开始学习FPGA----RAM IP的定制与测试

Mongodb learning chapter: introduction after installation lesson 1

busybox生成的东西
随机推荐
Unity 使用Sqlite
In depth understanding of condition source code interpretation and analysis of concurrent programming
Mathematical knowledge: finding the number of divisors
数据库连接池的简单实现
Thread process foundation of JUC
Lock free concurrency of JUC (leguan lock)
Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
[ffmpeg] [reprint] image mosaic: picture in picture with wheat
数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化
[SRS] use of Vhost isolated stream: push / pull Stream Address
Deeply understand the underlying implementation principle of countdownlatch in concurrent programming
QT等待框制作
Web Security (IX) what is JWT?
[Yugong series] February 2022 Net architecture class 005 ABP vNext Net core web application getting started configuration
Causes of short circuit of conductive slip ring and Countermeasures
boot+jsp的高校社团管理系统(附源码下载链接)
Simple implementation of database connection pool
如何创建一个根据进度改变颜色的进度条
数据治理:元数据管理实施(第四篇)
idea启动查看项目端口